Skip to content

fix(function_schema): support reserved param names#3572

Closed
Epochex wants to merge 4 commits into
openai:mainfrom
Epochex:fix/function-schema-reserved-param-names
Closed

fix(function_schema): support reserved param names#3572
Epochex wants to merge 4 commits into
openai:mainfrom
Epochex:fix/function-schema-reserved-param-names

Conversation

@Epochex
Copy link
Copy Markdown

@Epochex Epochex commented Jun 3, 2026

Fixes #3547.
Fixes #3549.

function_schema() currently breaks when a tool parameter uses Pydantic-reserved names:

  • model_config crashes during create_model()
  • model_dump / model_validate get rejected by protected namespace checks

This 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 -q
  • uv 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.py
  • uv 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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agents/function_schema.py
Comment thread src/agents/function_schema.py Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/agents/function_schema.py Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@seratch seratch added the wontfix This will not be worked on label Jun 4, 2026
@seratch seratch closed this Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:core wontfix This will not be worked on

Projects

None yet

2 participants