[PR #6788] fix(config): validate config type in ensure_config #5297

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

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

State: closed
Merged: No


Summary

Validate config type in ensure_config and raise a clear TypeError when a non-mapping is passed.

Problem

graph.invoke() / graph.stream() can fail with an internal AttributeError when config is not a mapping (e.g. a string), because ensure_config calls .items() unconditionally.

Changes

  • Add a type guard in ensure_config to reject non-mapping config values.
  • Raise TypeError with explicit message: config must be a mapping (RunnableConfig), got <type>.
  • Add regression test test_ensure_config_rejects_non_mapping in libs/langgraph/tests/test_utils.py.

Validation

  • NO_DOCKER=true pytest -q libs/langgraph/tests/test_utils.py -k "ensure_config_rejects_non_mapping"
  • NO_DOCKER=true pytest -q libs/langgraph/tests/test_utils.py -k "configurable_metadata or ensure_config_rejects_non_mapping"

Risk & Rollback

  • Low risk: only tightens input validation for invalid config types.
  • Rollback: revert this commit if needed.

Related

Fixes #6782

**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/6788 **State:** closed **Merged:** No --- ## Summary Validate `config` type in `ensure_config` and raise a clear `TypeError` when a non-mapping is passed. ## Problem `graph.invoke()` / `graph.stream()` can fail with an internal `AttributeError` when `config` is not a mapping (e.g. a string), because `ensure_config` calls `.items()` unconditionally. ## Changes - Add a type guard in `ensure_config` to reject non-mapping `config` values. - Raise `TypeError` with explicit message: `config must be a mapping (RunnableConfig), got <type>`. - Add regression test `test_ensure_config_rejects_non_mapping` in `libs/langgraph/tests/test_utils.py`. ## Validation - `NO_DOCKER=true pytest -q libs/langgraph/tests/test_utils.py -k "ensure_config_rejects_non_mapping"` - `NO_DOCKER=true pytest -q libs/langgraph/tests/test_utils.py -k "configurable_metadata or ensure_config_rejects_non_mapping"` ## Risk & Rollback - Low risk: only tightens input validation for invalid `config` types. - Rollback: revert this commit if needed. ## Related Fixes #6782
yindo added the pull-request label 2026-02-20 17:51:30 -05:00
yindo closed this issue 2026-02-20 17:51:30 -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#5297