langchain-ai/langchain · error · ValueError

If multiple pydantic schemas are provided then args_only sho

Error message

If multiple pydantic schemas are provided then args_only should be False.

What it means

Validation error from PydanticOutputFunctionsParser's field validator: you passed a dict of multiple named Pydantic schemas (function-name -> model mapping) together with args_only=True. With multiple schemas the parser must return the function name plus arguments, so returning arguments alone is ambiguous and rejected at init time.

Source

Thrown at libs/core/langchain_core/output_parsers/openai_functions.py:253

            values: The values to validate.

        Returns:
            The validated values.

        Raises:
            ValueError: If the schema is not a Pydantic schema.
        """
        schema = values["pydantic_schema"]
        if "args_only" not in values:
            values["args_only"] = isinstance(schema, type) and issubclass(
                schema, BaseModel
            )
        elif values["args_only"] and isinstance(schema, dict):
            msg = (
                "If multiple pydantic schemas are provided then args_only should be"
                " False."
            )
            raise ValueError(msg)
        return values

    @override
    def parse_result(self, result: list[Generation], *, partial: bool = False) -> Any:
        """Parse the result of an LLM call to a JSON object.

        Args:
            result: The result of the LLM call.
            partial: Whether to parse partial JSON objects.

        Raises:
            ValueError: If the Pydantic schema is not valid.

        Returns:
            The parsed JSON object.
        """
        result_ = super().parse_result(result)
        pydantic_args: PydanticBaseModel

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Set args_only=False (or omit it — it is auto-derived from the schema type) when passing a dict of schemas
  2. If you truly want arguments only, use a single Pydantic schema, not a dict of them

Example fix

# before
parser = PydanticOutputFunctionsParser(
    pydantic_schema={"create_person": Person, "create_book": Book},
    args_only=True,
)

# after
parser = PydanticOutputFunctionsParser(
    pydantic_schema={"create_person": Person, "create_book": Book},
    args_only=False,
)
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(pydantic_schema, dict):
    assert not args_only, "multi-schema dicts require args_only=False"

Prevention

When it happens

Trigger: Constructing PydanticOutputFunctionsParser(pydantic_schema={'fn_a': ModelA, 'fn_b': ModelB}, args_only=True) — the args_only=True combined with a dict schema trips the validator.

Common situations: Copy-pasting args_only=True from a single-schema example while switching to a multi-schema dict; assuming args_only applies per-function after a refactor.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/b4d55107da0573bd. Report an issue: GitHub.