langchain-ai/deepagents · error · ValueError

response_schema exceeds maximum of {_SCHEMA_MAX_PROPERTIES}

Error message

response_schema exceeds maximum of {_SCHEMA_MAX_PROPERTIES} properties

What it means

Schema validation also tracks a cumulative property count across every nested object and rejects `response_schema` when the total exceeds `_SCHEMA_MAX_PROPERTIES`. The count is shared via `prop_count[0]` across recursive `_check` calls, so the whole schema, not a single level, is bounded.

Source

Thrown at libs/partners/quickjs/langchain_quickjs/_subagent.py:299

            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):
                    _check(value, depth + 1, prop_count)
        items = node.get("items")
        if isinstance(items, dict):
            _check(items, depth + 1, prop_count)

    _check(schema, 0, [0])


_DEFAULT_SCHEMA_TITLE = "subagent_response"


def _ensure_schema_title(schema: dict[str, Any]) -> dict[str, Any]:
    """Ensure the response schema carries a non-empty top-level ``title``.

    Structured output backends that treat a JSON schema as a function (for
    example, the OpenAI function-calling path) require a top-level ``title`` to

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Trim the schema to only the properties the subagent must return.
  2. Group rarely used fields into a single `metadata` object or a JSON string field.
  3. Generate the schema programmatically and assert the total property count before calling `task()`.
  4. Check `_SCHEMA_MAX_PROPERTIES` for the exact allowed total.

Example fix

// before
props = {col: {"type": "string"} for col in all_500_table_columns}
schema = {"type": "object", "properties": props}

// after
needed = ["id", "name", "created_at"]
schema = {"type": "object", "properties": {c: {"type": "string"} for c in needed}}
Defensive patterns

Strategy: validation

Validate before calling

def count_props(node, acc=[0]):
    props = node.get("properties")
    if isinstance(props, dict):
        acc[0] += len(props)
        for v in props.values():
            if isinstance(v, dict):
                count_props(v, acc)
    items = node.get("items")
    if isinstance(items, dict):
        count_props(items, acc)
    return acc[0]
assert count_props(schema, [0]) <= _SCHEMA_MAX_PROPERTIES, "too many properties"

Try / catch

try:
    task(prompt=prompt, response_schema=schema)
except ValueError as e:
    if "properties" in str(e):
        task(prompt=prompt, response_schema=trim_schema_to_essential_fields(schema))

Prevention

When it happens

Trigger: Passing a `response_schema` whose combined number of `properties` entries across all nested objects exceeds `_SCHEMA_MAX_PROPERTIES` when calling `task()`.

Common situations: Auto-generating schemas from wide tables, API responses, or config formats with hundreds of fields; exporting an entire database row schema when only a few columns are needed.

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


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/7711be2970a096e7. Report an issue: GitHub.