fix(function_schema): support reserved param names#3572
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0f76744751
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a754851895
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: abbd54de53
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def _with_field_alias(field_info: FieldInfo, alias: str) -> FieldInfo: | ||
| """Returns a copy of a field definition with an explicit validation/serialization alias.""" | ||
|
|
||
| return FieldInfo.merge_field_infos(field_info, Field(alias=alias)) |
There was a problem hiding this comment.
Preserve aliases when aliasing reserved params
When a reserved parameter also has a user-specified Field(alias=...) (for example model_dump: str = Field(alias="payload")), this helper is called after merging that FieldInfo and replaces the public alias with the Python parameter name. The generated schema then exposes/validates model_dump instead of payload, making Field alias behavior depend on whether the parameter name happens to be Pydantic-protected; preserve an existing validation/serialization alias while still mapping the internal field back for to_call_args().
Useful? React with 👍 / 👎.
Fixes #3547.
Fixes #3549.
function_schema()currently breaks when a tool parameter uses Pydantic-reserved names:model_configcrashes duringcreate_model()model_dump/model_validateget rejected by protected namespace checksThis keeps the public tool schema names unchanged, but aliases those parameters to internal safe field names inside the generated Pydantic model.
to_call_args()then maps back to the original function signature.Tests:
uv run --project C:\Users\lin\Desktop\Github_Dev\openai-agents-python pytest C:\Users\lin\Desktop\Github_Dev\openai-agents-python\tests\test_function_schema.py -quv run --project C:\Users\lin\Desktop\Github_Dev\openai-agents-python ruff check C:\Users\lin\Desktop\Github_Dev\openai-agents-python\src\agents\function_schema.py C:\Users\lin\Desktop\Github_Dev\openai-agents-python\tests\test_function_schema.pyuv run --project C:\Users\lin\Desktop\Github_Dev\openai-agents-python pyright C:\Users\lin\Desktop\Github_Dev\openai-agents-python\src\agents\function_schema.py