Skip to content

fix: preserve Field constraints on variadic tool parameters - #4739

Open
rioyu123 wants to merge 1 commit into
openai:mainfrom
rioyu123:fix/tool-field-constraints
Open

fix: preserve Field constraints on variadic tool parameters#4739
rioyu123 wants to merge 1 commit into
openai:mainfrom
rioyu123:fix/tool-field-constraints

Conversation

@rioyu123

Copy link
Copy Markdown

This pull request fixes lost Pydantic Field constraints on variadic tool parameters.

For example, *scores: Annotated[int, Field(ge=0)] currently produces an unconstrained item schema and allows negative values to reach the tool callable. The same issue affects values collected through **kwargs.

The fix preserves the existing Field constraint metadata on each positional item or keyword value when building the Pydantic model. As a result, the generated JSON schema and runtime validation both enforce the declared constraints, and invalid values are rejected before the callable runs.

This is intentionally narrower than #4609: it only covers the existing supported Annotated[T, Field(...)] form for *args and **kwargs. It does not add support for arbitrary outer Annotated metadata.

Ordinary parameters, defaults and aliases, argument reconstruction, description precedence, existing tuple handling, and strict-schema behavior for arbitrary-key **kwargs remain unchanged.

Test plan

  • Added regression coverage for *args and **kwargs constraints in both generated schemas and actual tool invocation.
  • Covered numeric bounds, string length constraints, valid and invalid values, omitted/empty variadic arguments, and existing tuple behavior.
  • Full repository verification passes, including formatting, linting, Mypy, Pyright, and the test suite.
  • Python 3.10 smoke checks pass for both variadic forms.

Related context

#4609

Checks

  • Added regression tests.
  • Ran .agents/skills/code-change-verification/scripts/run.sh.
  • Confirmed the full verification suite passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant