[PR #6783] fix(langgraph): validate config type before invoke and stream #5291

Closed
opened 2026-02-20 17:51:29 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/6783

State: closed
Merged: No


Summary

Fixes #6782.

graph.invoke() / graph.stream() currently crash with an internal AttributeError when config is not a mapping (for example, a string).

This PR adds explicit config-type validation and returns a clear user-facing TypeError instead.

Changes

  • Add runtime validation in ensure_config(...):
    • raise TypeError("Expected config to be a mapping, got <type>") for non-mapping config values.
  • Normalize config earlier in both sync and async stream paths:
    • call ensure_config(self.config, config) before checking stream_mode defaults.
    • this prevents pre-validation access via config.get(...) on invalid types.
  • Add regression tests:
    • test_ensure_config_rejects_non_mapping
    • test_graph_rejects_non_mapping_config (covers both graph.invoke and graph.stream)

Validation

Executed locally in libs/langgraph:

  • make format
  • make lint
  • NO_DOCKER=true TEST=tests/test_utils.py make test
  • uv run python -m trace --count --coverdir /tmp/langgraph_6782_trace --module pytest tests/test_utils.py -q

The new failure path and stream/invoke guard paths are covered by the added tests.

AI involvement

AI assistance was limited to unit-test drafting, code-review suggestions, and formatting checks. Final implementation and code decisions were manually completed and verified.

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6783 **State:** closed **Merged:** No --- ## Summary Fixes #6782. `graph.invoke()` / `graph.stream()` currently crash with an internal `AttributeError` when `config` is not a mapping (for example, a string). This PR adds explicit config-type validation and returns a clear user-facing `TypeError` instead. ## Changes - Add runtime validation in `ensure_config(...)`: - raise `TypeError("Expected config to be a mapping, got <type>")` for non-mapping config values. - Normalize config earlier in both sync and async stream paths: - call `ensure_config(self.config, config)` before checking `stream_mode` defaults. - this prevents pre-validation access via `config.get(...)` on invalid types. - Add regression tests: - `test_ensure_config_rejects_non_mapping` - `test_graph_rejects_non_mapping_config` (covers both `graph.invoke` and `graph.stream`) ## Validation Executed locally in `libs/langgraph`: - `make format` - `make lint` - `NO_DOCKER=true TEST=tests/test_utils.py make test` - `uv run python -m trace --count --coverdir /tmp/langgraph_6782_trace --module pytest tests/test_utils.py -q` The new failure path and stream/invoke guard paths are covered by the added tests. ## AI involvement AI assistance was limited to unit-test drafting, code-review suggestions, and formatting checks. Final implementation and code decisions were manually completed and verified.
yindo added the pull-request label 2026-02-20 17:51:29 -05:00
yindo closed this issue 2026-02-20 17:51:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#5291