openai/openai-python · error · ValueError

warnings is only supported in Pydantic v2

Error message

warnings is only supported in Pydantic v2

What it means

In the Pydantic v1 compat shim for model_dump, the warnings keyword is accepted only at its default (True); passing warnings=False — the common Pydantic v2 usage to silence serialization warnings — is unsupported and raises ValueError.

Source

Thrown at src/openai/_models.py:353

                exclude_computed_fields: Whether to exclude computed fields.
                    While this can be useful for round-tripping, it is usually recommended to use the dedicated
                    `round_trip` parameter instead.
                round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
                warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
                    "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
                fallback: A function to call when an unknown value is encountered. If not provided,
                    a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
                serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.

            Returns:
                A dictionary representation of the model.
            """
            if mode not in {"json", "python"}:
                raise ValueError("mode must be either 'json' or 'python'")
            if round_trip != False:
                raise ValueError("round_trip is only supported in Pydantic v2")
            if warnings != True:
                raise ValueError("warnings is only supported in Pydantic v2")
            if context is not None:
                raise ValueError("context is only supported in Pydantic v2")
            if serialize_as_any != False:
                raise ValueError("serialize_as_any is only supported in Pydantic v2")
            if fallback is not None:
                raise ValueError("fallback is only supported in Pydantic v2")
            if exclude_computed_fields != False:
                raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
            dumped = super().dict(  # pyright: ignore[reportDeprecated]
                include=include,
                exclude=exclude,
                by_alias=by_alias if by_alias is not None else False,
                exclude_unset=exclude_unset,
                exclude_defaults=exclude_defaults,
                exclude_none=exclude_none,
            )

            return cast("dict[str, Any]", json_safe(dumped)) if mode == "json" else dumped

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Drop warnings=False under Pydantic v1
  2. Upgrade to pydantic>=2 where warnings=False is honored

Example fix

# before
d = obj.model_dump(warnings=False)
# after
d = obj.model_dump()
Defensive patterns

Strategy: validation

Validate before calling

import pydantic
if pydantic.VERSION.startswith('1.'):
    kwargs.pop('warnings', None)
obj.model_dump(**kwargs)

Prevention

When it happens

Trigger: Calling model.model_dump(warnings=False) on SDK models under Pydantic v1.

Common situations: Suppressing Pydantic v2 serialization warnings by porting warnings=False into a project still on Pydantic v1.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/1ea7cdbc3b16c9d9. Report an issue: GitHub.