langchain-ai/deepagents · error · ValueError
response_schema exceeds {_SCHEMA_MAX_BYTES} byte limit ({len
Error message
response_schema exceeds {_SCHEMA_MAX_BYTES} byte limit ({len(serialized)} bytes) What it means
`_validate_response_schema` serializes the caller's JSON Schema with `json.dumps` and enforces a maximum size of `_SCHEMA_MAX_BYTES`. Oversized schemas are rejected with `ValueError` before being handed to the subagent runtime, keeping prompts and provider payloads bounded.
Source
Thrown at libs/partners/quickjs/langchain_quickjs/_subagent.py:283
"phase": "complete",
"id": subagent_id,
"duration_ms": int((time.monotonic() - started_at) * 1000),
}
if eval_id is not None:
complete_event["eval_id"] = eval_id
_emit_subagent_event(stream_writer, complete_event)
return output
def _validate_response_schema(schema: dict[str, Any]) -> None:
"""Reject schemas that exceed size, depth, or property-count limits."""
serialized = json.dumps(schema)
if len(serialized) > _SCHEMA_MAX_BYTES:
msg = (
f"response_schema exceeds {_SCHEMA_MAX_BYTES}"
f" byte limit ({len(serialized)} bytes)"
)
raise ValueError(msg)
def _check(node: dict[str, Any], depth: int, prop_count: list[int]) -> None:
if depth > _SCHEMA_MAX_DEPTH:
msg = (
f"response_schema exceeds maximum nesting depth of {_SCHEMA_MAX_DEPTH}"
)
raise ValueError(msg)
props = node.get("properties")
if isinstance(props, dict):
prop_count[0] += len(props)
if prop_count[0] > _SCHEMA_MAX_PROPERTIES:
msg = (
"response_schema exceeds maximum of"
f" {_SCHEMA_MAX_PROPERTIES} properties"
)
raise ValueError(msg)
for value in props.values():
if isinstance(value, dict):View on GitHub (pinned to a1af029e6e)
Solutions
- Shrink the schema to the minimal structure you need — describe only the fields you will consume.
- Move large shared definitions out (or reference them by name) and deduplicate repeated subtrees.
- Split the extraction into multiple `task()` calls with smaller schemas.
- If the limit is genuinely too small, check `_SCHEMA_MAX_BYTES` for the current bound and raise a targeted issue rather than bypassing validation.
Example fix
// before
schema = load_entire_openapi_schema() # ~200 KB
task(prompt="extract user", response_schema=schema)
// after
schema = {"type": "object", "properties": {"name": {"type": "string"}, "email": {"type": "string"}}}
task(prompt="extract user", response_schema=schema) Defensive patterns
Strategy: validation
Validate before calling
import json
serialized = json.dumps(schema)
if len(serialized.encode()) > _SCHEMA_MAX_BYTES:
raise ValueError("response_schema too large; trim to required fields") Try / catch
try:
task(prompt=prompt, response_schema=schema)
except ValueError as e:
if "byte limit" in str(e):
task(prompt=prompt, response_schema=minify_schema(schema)) Prevention
- Keep schemas minimal — only fields you consume.
- Deduplicate `$defs` and remove embedded examples.
- Compute `len(json.dumps(schema))` before large calls in hot paths.
When it happens
Trigger: Passing a `response_schema` larger than `_SCHEMA_MAX_BYTES` to `task()` (via `call_subagent_task_tool`), typically an inlined mega-schema, a schema with embedded data/examples, or a duplicated deeply-nested schema object.
Common situations: Generating schemas programmatically that balloon with `$defs` repetition; pasting a full OpenAPI-derived schema where a small response shape was intended; embedding sample payloads inside the schema.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- response_schema exceeds maximum nesting depth of {_SCHEMA_MA
- response_schema exceeds maximum of {_SCHEMA_MAX_PROPERTIES}
- Could not parse embedded resource block. Block expected eith
- {question_type} question {question_text!r} must not define '
- Unknown external event kind: {self.kind!r}
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/b81c8dd067748c0b.
Report an issue: GitHub.