{"record":{"id":"b81c8dd067748c0b","repo":"langchain-ai/deepagents","slug":"response-schema-exceeds-schema-max-bytes-byte-l","errorCode":null,"errorMessage":"response_schema exceeds {_SCHEMA_MAX_BYTES} byte limit ({len(serialized)} bytes)","messagePattern":"response_schema exceeds (.+?) byte limit \\((.+?) bytes\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/partners/quickjs/langchain_quickjs/_subagent.py","lineNumber":283,"sourceCode":"        \"phase\": \"complete\",\n        \"id\": subagent_id,\n        \"duration_ms\": int((time.monotonic() - started_at) * 1000),\n    }\n    if eval_id is not None:\n        complete_event[\"eval_id\"] = eval_id\n    _emit_subagent_event(stream_writer, complete_event)\n    return output\n\n\ndef _validate_response_schema(schema: dict[str, Any]) -> None:\n    \"\"\"Reject schemas that exceed size, depth, or property-count limits.\"\"\"\n    serialized = json.dumps(schema)\n    if len(serialized) > _SCHEMA_MAX_BYTES:\n        msg = (\n            f\"response_schema exceeds {_SCHEMA_MAX_BYTES}\"\n            f\" byte limit ({len(serialized)} bytes)\"\n        )\n        raise ValueError(msg)\n\n    def _check(node: dict[str, Any], depth: int, prop_count: list[int]) -> None:\n        if depth > _SCHEMA_MAX_DEPTH:\n            msg = (\n                f\"response_schema exceeds maximum nesting depth of {_SCHEMA_MAX_DEPTH}\"\n            )\n            raise ValueError(msg)\n        props = node.get(\"properties\")\n        if isinstance(props, dict):\n            prop_count[0] += len(props)\n            if prop_count[0] > _SCHEMA_MAX_PROPERTIES:\n                msg = (\n                    \"response_schema exceeds maximum of\"\n                    f\" {_SCHEMA_MAX_PROPERTIES} properties\"\n                )\n                raise ValueError(msg)\n            for value in props.values():\n                if isinstance(value, dict):","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/partners/quickjs/langchain_quickjs/_subagent.py#L265-L301","documentation":"`_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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nschema = load_entire_openapi_schema()  # ~200 KB\ntask(prompt=\"extract user\", response_schema=schema)\n\n// after\nschema = {\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}, \"email\": {\"type\": \"string\"}}}\ntask(prompt=\"extract user\", response_schema=schema)","handlingStrategy":"validation","validationCode":"import json\nserialized = json.dumps(schema)\nif len(serialized.encode()) > _SCHEMA_MAX_BYTES:\n    raise ValueError(\"response_schema too large; trim to required fields\")","typeGuard":null,"tryCatchPattern":"try:\n    task(prompt=prompt, response_schema=schema)\nexcept ValueError as e:\n    if \"byte limit\" in str(e):\n        task(prompt=prompt, response_schema=minify_schema(schema))","preventionTips":["Keep schemas minimal — only fields you consume.","Deduplicate `$defs` and remove embedded examples.","Compute `len(json.dumps(schema))` before large calls in hot paths."],"tags":["validation","schema","limits","subagent"],"backgroundTag":"schema-validation-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}