{"record":{"id":"ef92b641d119f2f6","repo":"openai/openai-python","slug":"mode-must-be-either-json-or-python","errorCode":null,"errorMessage":"mode must be either 'json' or 'python'","messagePattern":"mode must be either 'json' or 'python'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/openai/_models.py","lineNumber":349,"sourceCode":"                by_alias: Whether to use the field's alias in the dictionary key if defined.\n                exclude_unset: Whether to exclude fields that have not been explicitly set.\n                exclude_defaults: Whether to exclude fields that are set to their default value.\n                exclude_none: Whether to exclude fields that have a value of `None`.\n                exclude_computed_fields: Whether to exclude computed fields.\n                    While this can be useful for round-tripping, it is usually recommended to use the dedicated\n                    `round_trip` parameter instead.\n                round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].\n                warnings: How to handle serialization errors. False/\"none\" ignores them, True/\"warn\" logs errors,\n                    \"error\" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].\n                fallback: A function to call when an unknown value is encountered. If not provided,\n                    a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.\n                serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.\n\n            Returns:\n                A dictionary representation of the model.\n            \"\"\"\n            if mode not in {\"json\", \"python\"}:\n                raise ValueError(\"mode must be either 'json' or 'python'\")\n            if round_trip != False:\n                raise ValueError(\"round_trip is only supported in Pydantic v2\")\n            if warnings != True:\n                raise ValueError(\"warnings is only supported in Pydantic v2\")\n            if context is not None:\n                raise ValueError(\"context is only supported in Pydantic v2\")\n            if serialize_as_any != False:\n                raise ValueError(\"serialize_as_any is only supported in Pydantic v2\")\n            if fallback is not None:\n                raise ValueError(\"fallback is only supported in Pydantic v2\")\n            if exclude_computed_fields != False:\n                raise ValueError(\"exclude_computed_fields is only supported in Pydantic v2\")\n            dumped = super().dict(  # pyright: ignore[reportDeprecated]\n                include=include,\n                exclude=exclude,\n                by_alias=by_alias if by_alias is not None else False,\n                exclude_unset=exclude_unset,\n                exclude_defaults=exclude_defaults,","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_models.py#L331-L367","documentation":"The SDK's Pydantic v1 compatibility shim for model_dump only accepts mode='json' or mode='python'. Any other mode string (or a typo) is rejected immediately before serialization begins.","triggerScenarios":"Calling model.model_dump(mode='json-mode'), mode='' , or any value outside {'json','python'} on any SDK model object (e.g. ChatCompletion, Model).","commonSituations":"Confusing this API with other libraries' mode names; passing None or an unset config value as mode.","solutions":["Use mode='json' for JSON-safe primitives or mode='python' for native objects","Omit mode entirely if the default is acceptable"],"exampleFix":"# before\nd = obj.model_dump(mode='raw')\n# after\nd = obj.model_dump(mode='json')\n","handlingStrategy":"validation","validationCode":"mode = kwargs.get('mode', 'python')\nassert mode in {'json', 'python'}, f\"bad mode: {mode}\"","typeGuard":"def is_valid_mode(m: str) -> bool:\n    return m in {'json', 'python'}","tryCatchPattern":null,"preventionTips":["Restrict mode to literal 'json' or 'python'; avoid passing config-driven strings unchecked"],"tags":["pydantic","serialization","models","v1-compat"],"backgroundTag":"invalid-serialization-argument","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}