langchain-ai/langchain · error · ValueError

Dict Pydantic schema unsupported with args_only: {self.pydan

Error message

Dict Pydantic schema unsupported with args_only: {self.pydantic_schema}

What it means

Runtime error in PydanticOutputFunctionsParser.parse_result with args_only=True when pydantic_schema is a dict. This state is normally blocked by the init-time validator (error 185), so seeing it at parse time means the validator was bypassed — e.g. the field was mutated after construction (parser.pydantic_schema = {...}) or object was created via model_construct / deserialization that skips validation.

Source

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

        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
        if self.args_only:
            if isinstance(self.pydantic_schema, dict):
                msg = (
                    "Dict Pydantic schema unsupported with args_only: "
                    f"{self.pydantic_schema}"
                )
                raise ValueError(msg)
            if issubclass(self.pydantic_schema, BaseModel):
                pydantic_args = self.pydantic_schema.model_validate_json(result_)
            elif issubclass(self.pydantic_schema, BaseModelV1):
                pydantic_args = self.pydantic_schema.parse_raw(result_)
            else:
                msg = (  # type: ignore[unreachable]
                    "Unsupported Pydantic schema with args_only: "
                    f"{self.pydantic_schema}"
                )
                raise ValueError(msg)
        else:
            fn_name = result_["name"]
            args = result_["arguments"]
            if isinstance(self.pydantic_schema, dict):
                pydantic_schema = self.pydantic_schema[fn_name]
            else:
                pydantic_schema = self.pydantic_schema
            if issubclass(pydantic_schema, BaseModel):

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Set args_only=False whenever the schema is (or becomes) a dict of multiple schemas
  2. Recreate the parser instance instead of mutating pydantic_schema in place
  3. Revalidate configuration after deserialization (e.g. call model_validate on the reconstructed parser)

Example fix

# before
parser = PydanticOutputFunctionsParser(pydantic_schema=Person, args_only=True)
parser.pydantic_schema = {"a": A, "b": B}  # mutation skips validator

# after
parser = PydanticOutputFunctionsParser(pydantic_schema={"a": A, "b": B}, args_only=False)
Defensive patterns

Strategy: validation

Validate before calling

if parser.args_only and isinstance(parser.pydantic_schema, dict):
    raise ValueError("reconfigure parser with args_only=False")

Prevention

When it happens

Trigger: Assigning a dict to parser.pydantic_schema after construction while args_only stays True; building the parser with Pydantic model_construct or deserializing state that skips field validators.

Common situations: Dynamically swapping schemas at runtime on an existing parser instance; loading parser configs from serialized state without revalidation.

Related errors


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