docs: describe Pydantic Field annotations for tool args#2436
docs: describe Pydantic Field annotations for tool args#2436haasonsaas wants to merge 1 commit intoopenai:mainfrom
Conversation
Document both default-based and Annotated forms for constraining and describing function-tool arguments (addresses review request in PR openai#1124).
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d36b46f6a5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| # Annotated form | ||
| @function_tool | ||
| def score_b(score: Annotated[int, Field(..., ge=0, le=100, description="Score from 0 to 100")]) -> str: | ||
| return f"Score recorded: {score}" |
There was a problem hiding this comment.
Remove claim that Annotated Field constraints are applied
The docs state that the Annotated form (Annotated[int, Field(..., ge=1)]) is supported and that constraints are included in the generated schema, but function_schema currently strips Annotated metadata via _strip_annotated() and only keeps string metadata for descriptions. This means Field(...) inside Annotated is discarded, so constraints like ge/le are not applied to tool args. Unless the runtime is updated to preserve Field metadata from Annotated, this example is misleading and can cause users to believe constraints will be enforced when they will not.
Useful? React with 👍 / 👎.
|
Docs PR is green and pairs nicely with #2435. Ready to merge when a maintainer can. |
Docs follow-up for #2428 / #2435.
Keeps documentation changes separate so runtime changes can merge independently from doc/release cadence.