openai/openai-python · error · ValueError

round_trip is only supported in Pydantic v2

Error message

round_trip is only supported in Pydantic v2

What it means

In the Pydantic v1 compatibility implementation of model_dump, the round_trip keyword exists for signature parity with Pydantic v2 but is not supported; only the default False is accepted, and any other value raises ValueError.

Source

Thrown at src/openai/_models.py:351

                exclude_defaults: Whether to exclude fields that are set to their default value.
                exclude_none: Whether to exclude fields that have a value of `None`.
                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,
            )

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Remove round_trip=True (or set it to False) when running under Pydantic v1
  2. Upgrade the environment to pydantic>=2 so the v2 implementation honoring round_trip is used

Example fix

# before
d = obj.model_dump(round_trip=True)
# after
d = obj.model_dump()
Defensive patterns

Strategy: validation

Validate before calling

import pydantic
if pydantic.VERSION.startswith('1.'):
    kwargs.pop('round_trip', None)  # not supported under v1
obj.model_dump(**kwargs)

Prevention

When it happens

Trigger: Calling model.model_dump(round_trip=True) on an SDK model when the environment resolves to the Pydantic v1 compat layer.

Common situations: Copying Pydantic v2 example code (round_trip=True) into a project pinned to pydantic v1; upgrading the SDK but not pydantic.

Related errors


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