langchain-ai/langchain · error · ValueError
Invalid format: {self._schema_format}
Error message
Invalid format: {self._schema_format} What it means
Raised by BaseLangChainTracer._get_chain_inputs when normalizing chain run inputs for a tracer whose _schema_format is not one of the supported values ('original', 'original+chat', 'streaming_events'). The tracer cannot decide whether to wrap non-dict inputs under an 'input' key or pass them through, so it refuses to record the run. It indicates a misconstructed or version-mismatched tracer rather than bad user data.
Source
Thrown at libs/core/langchain_core/tracers/core.py:387
extra=kwargs,
events=[{"name": "start", "time": start_time}],
start_time=start_time,
child_runs=[],
run_type=run_type or "chain",
name=name,
tags=tags or [],
)
def _get_chain_inputs(self, inputs: Any) -> Any:
"""Get the inputs for a chain run."""
if self._schema_format in {"original", "original+chat"}:
return inputs if isinstance(inputs, dict) else {"input": inputs}
if self._schema_format == "streaming_events":
return {
"input": inputs,
}
msg = f"Invalid format: {self._schema_format}"
raise ValueError(msg)
def _get_chain_outputs(self, outputs: Any) -> Any:
"""Get the outputs for a chain run."""
if self._schema_format in {"original", "original+chat"}:
return outputs if isinstance(outputs, dict) else {"output": outputs}
if self._schema_format == "streaming_events":
return {
"output": outputs,
}
msg = f"Invalid format: {self._schema_format}"
raise ValueError(msg)
def _complete_chain_run(
self,
outputs: dict[str, Any],
run_id: UUID,
inputs: dict[str, Any] | None = None,
) -> Run:View on GitHub (pinned to e32fa9a52e)
Solutions
- Do not set _schema_format yourself; use the default ('original') or the documented values 'original+chat' / 'streaming_events'
- If subclassing, validate the value in __init__ against {'original','original+chat','streaming_events'} and raise early
- Align versions: uv sync so every langchain-* package uses the same langchain-core version
- If you need a custom input schema, override _get_chain_inputs/_get_chain_outputs entirely instead of inventing a format string
Example fix
// before
class MyTracer(BaseLangChainTracer):
def __init__(self):
self._schema_format = "my_format"
// after
class MyTracer(BaseLangChainTracer):
def __init__(self):
self._schema_format = "original" # or 'streaming_events' Defensive patterns
Strategy: validation
Validate before calling
VALID_FORMATS = {"original", "original+chat", "streaming_events"}
assert tracer._schema_format in VALID_FORMATS, tracer._schema_format Type guard
def is_valid_schema_format(fmt: str) -> bool:
return fmt in {"original", "original+chat", "streaming_events"} Prevention
- Never assign custom strings to _schema_format; treat it as an internal, closed enum
- Validate tracer configuration in __init__ of subclasses, not mid-run
- Keep one langchain-core version across the environment (uv sync)
When it happens
Trigger: Instantiating BaseLangChainTracer (or a subclass) and setting _schema_format to an arbitrary/custom string; passing a tracer built against a newer langchain-core (which introduced new formats) into an older runtime that does not recognize it; calling on_chain_start with such a tracer attached to config['callbacks'].
Common situations: Custom tracer subclasses that override __init__ and set _schema_format from a constructor kwarg without validating it; mixing langchain-core versions in one environment (e.g. a partner package pinning an older core); copy-pasted tracer code from a different core version.
Related errors
- Tracing using LangChainTracerV1 is no longer supported. Plea
- Could not resolve content_key {full_path!r}: expected a mapp
- Could not resolve content_key {full_path!r}: missing key {ke
- If env_var is set, handle_class must also be set to a non-No
- A pending deprecation cannot have a scheduled removal
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/e25aa7faa89e48b9.
Report an issue: GitHub.