langchain-ai/langgraph · error · ValueError
Invalid context schema type
Error message
Invalid context schema type: {context_schema}. Must be a BaseModel, TypedDict or dataclass. What it means
Raised by get_context_jsonschema when the graph's context_schema is not a supported schema type. Only Pydantic BaseModel subclasses, TypedDicts, and dataclasses can be converted to JSON Schema; any other type annotation passed as context_schema fails here. Provide one of the supported schema types.
Solutions
- Define context_schema as a pydantic BaseModel, TypedDict, or dataclass
- Skip JSON-schema generation if an arbitrary type must be used
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at libs/langgraph/langgraph/pregel/main.py:1003 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of langchain-ai/langgraph@38031739e5 (2026-08-26).
Data as JSON: /api/errors/94c70857ad7974a2.
Report an issue: GitHub.
Appendix: source
Thrown at libs/langgraph/langgraph/pregel/main.py:1003
category=LangGraphDeprecatedSinceV10,
stacklevel=2,
)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=LangGraphDeprecatedSinceV10)
schema = self.config_schema(include=include)
return schema.model_json_schema()
def get_context_jsonschema(self) -> dict[str, Any] | None:
if (context_schema := self.context_schema) is None:
return None
if isclass(context_schema) and issubclass(context_schema, BaseModel):
return context_schema.model_json_schema()
elif is_typeddict(context_schema) or is_dataclass(context_schema):
return TypeAdapter(context_schema).json_schema()
else:
raise ValueError(
f"Invalid context schema type: {context_schema}. Must be a BaseModel, TypedDict or dataclass."
)
@property
def InputType(self) -> Any:
if isinstance(self.input_channels, str):
channel = self.channels[self.input_channels]
if isinstance(channel, BaseChannel):
return channel.UpdateType
def get_input_schema(self, config: RunnableConfig | None = None) -> type[BaseModel]:
config = merge_configs(self.config, config)
if isinstance(self.input_channels, str):
return super().get_input_schema(config)
else:
return create_model(
self.get_name("Input"),
field_definitions={View on GitHub (pinned to 38031739e5)