Keep output functions with a single aliased parameter from raising `KeyError`, and pass `**kwargs` and `SkipJsonSchema` argument values through

Merged
DS
22d ago
+212-31

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Closes #12334

Why we make these changes

An output function whose one parameter has a Pydantic alias failed with KeyError in every output mode. FunctionSchema.single_field_name took the wrapper key from the JSON schema, where the property is named after the alias, but validated arguments are keyed by the Python name. TextOutput read the same key and called the function with the alias. The single-field count also came from the JSON schema, so a function with **kwargs or a SkipJsonSchema parameter counted as single-argument and lost those values.

_build_schema now reports the single field from the branch that already decides it: exactly one field and no **kwargs, named by its Python name. function_schema drops it when the JSON schema leaves that field out, so a sole SkipJsonSchema parameter keeps its validated args whole.

Thanks to @gouyu-hou for https://github.com/pydantic/pydantic-ai/pull/12337, which found the cause and the stored-field shape this PR keeps (co-authored). #12337 still counted JSON properties, which turns def f(a: SkipJsonSchema[int] = 1, b: int = 2) sent {"b": 5} into b=2; main and this PR give b=5.

Deliberately out of scope, as on main: TextOutput with an aliased str param next to a SkipJsonSchema or **kwargs param, or with a model-like param (https://github.com/pydantic/pydantic-ai/issues/13331), and durable revalidation of aliased function-tool args (https://github.com/pydantic/pydantic-ai/issues/13324).

New public surface

none

User-visible behavior

def answer(city: Annotated[str, Field(alias='cityName')]) -> str: ...
Agent(model, output_type=answer)  # model sends {"cityName": "Paris"}
# before: KeyError: 'cityName'    after: answer(city='Paris')

def collect(a: int, **kwargs: int) -> dict[str, int]: ...  # model sends {"a": 1, "x": 2}
# before: collect(a=1)           after: collect(a=1, x=2)

Verification

What changes for existing users

Output functions with a single aliased parameter work in every output mode, including streaming and TextOutput, and output functions with **kwargs or a second SkipJsonSchema parameter get every value the model sends, with output hooks receiving their arguments as a dict like any multi-argument output function.

PR decisions

2026-11-13 · single-field rule from Python fields · iter -

  • Decision: single_field_name comes from schema_context.fields via _build_schema's own branch: 'len(fields) == 1 and var_kwargs_schema is None'; never count json_schema['properties']
  • Why: JSON property key is the validation alias and omits SkipJsonSchema params and **kwargs; validated args are keyed by Python name (validator v2, reproduced on main 6d334062f)
  • Source: https://github.com/pydantic/pydantic-ai/issues/12334
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · fold TextOutput sibling · iter -

  • Decision: TextFunctionOutputProcessor calls by Python name (single_field_name when the param is not model-like); keeps main's acceptance check (one JSON property, type == 'string')
  • Why: same root cause; gating acceptance on the new rule would reject def f(text: str, b: SkipJsonSchema[int]=1) and def f(text: str, **kw), which work on main
  • Source: https://github.com/pydantic/pydantic-ai/issues/12334
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · fold **kwargs / SkipJsonSchema data loss · iter -

  • Decision: def f(a, **kwargs) and def f(a, b: SkipJsonSchema[int]=1) are multi-field: no unwrap key, values kept; each gets a test that fails on main
  • Why: same property read off the JSON schema silently drops values on main
  • Source: https://github.com/pydantic/pydantic-ai/issues/12334
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · regression guard: hidden-first param · iter -

2026-11-13 · close #12337, open our own · iter -

2026-11-13 · split revalidate alias failure · iter -

  • Decision: FunctionSchema.revalidate on an aliased function tool stays out of this PR; reproduce through durable_exec/_toolset.py revalidate_function_args and file via /file-followup-issue (no labels, no assignee) only if it reproduces
  • Why: different surface (durable-exec boundary); validator checked it at unit level only
  • Source: https://github.com/pydantic/pydantic-ai/issues/12334
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · pre-push review 1 of 3 at ca3e3c2087fa7c84f3c655fddf4326bbf16865b8 · iter -

2026-11-13 · pre-push review 1 of 3 at ca3e3c2087fa7c84f3c655fddf4326bbf16865b8 · iter -

  • Decision: 4 findings: remediated 2 (TextOutput test moved to tests/test_agent.py; clearer comment), body-only 1 (name hook-dict change for **kwargs/SkipJsonSchema signatures), skipped 1 (aliased str + extra hidden/**kwargs TextOutput param: fails identically on main; reported to manager as sibling defect)
  • Why: Reviewed tree a6098e585561f24218dea6f62a8741714060e4e8; full branch 6d334062f..ca3e3c208; fresh claude -p haiku from detached policy base; both checkouts clean and unchanged after review; first launch errored before reviewing (prompt swallowed by variadic flag) and was relaunched under the same reservation
  • Source: https://github.com/pydantic/pydantic-ai/tree/aliased-output-arg
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · exempt delta ca3e3c208..e0932f4e4 chains from reviewed ca3e3c2087fa7c84f3c655fddf4326bbf16865b8 · iter -

  • Decision: No re-review: test relocation (test code only, same assertions) plus one comment line in _output.py
  • Why: Rubric rungs public API, behavior, docs untouched: git diff ca3e3c208..HEAD -- pydantic_ai_slim/ is one comment line; tests/ change moves test_text_output_function_str_arg verbatim into tests/test_agent.py; affected tests rerun and pass. Budget used: 1 of 3
  • Source: https://github.com/pydantic/pydantic-ai/tree/aliased-output-arg
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · defer: durable revalidation of aliased function-tool args · iter -

2026-11-13 · douwebot TextOutput finding A: split · iter -

  • Decision: Aliased str param next to a SkipJsonSchema/**kwargs param in TextOutput stays as on main; follow-up https://github.com/pydantic/pydantic-ai/issues/13331 (no labels, no assignee)
  • Why: Fails the same way on main and needs a new fix shape (a JSON-property to Python-name mapping on FunctionSchema); douwebot's validate-in-call variant would change TextOutput functions that work on main (maintainer dsfaccini via manager)
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · douwebot TextOutput finding B: keep main's behavior · iter -

2026-11-13 · exempt delta e0932f4e4..219da569e: target-branch merge · iter -

  • Decision: No re-review: merge of upstream/main 75ef1a9bd with no conflicts; new head needed because douwebot never re-reviews a head that carries its findings (bots.yml prior-findings)
  • Why: git diff merge-base..HEAD equals the PR diff at e0932f4e4 (index lines aside); exemption still chains from reviewed ca3e3c208. Budget used: 1 of 3
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · exempt delta 219da569e..3b30ed85a: test annotation · iter -

  • Decision: No re-review: PR Review Checks high finding fixed (output_type: Any -> OutputSpec[str] in test_function_aliased_arg_output_modes)
  • Why: Test code only, same assertions; pyright clean, TestHookSemanticValue passes; exemption chains from reviewed ca3e3c208. Budget used: 1 of 3
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323#discussion_r4558803016
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · douwebot optional: sole SkipJsonSchema param unwraps · iter -

  • Decision: Keep: def f(a: SkipJsonSchema[int] = 1) is single-field under the settled rule, so hooks see 1 instead of {'a': 1}; output unchanged (a=1); disclosed in the PR body, no push
  • Why: Follows from settled 'len(fields) == 1 and var_kwargs_schema is None' with no JSON-property count; finding is Optional and the dispatch says not to push for one; verified on main vs head with local-notes/sole_hidden.py
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323#discussion_r4558998335
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · regression 1: sole SkipJsonSchema param unwrapped · iter -

  • Decision: Supersedes the 'keep' entry: def f(a: SkipJsonSchema[int] = 1) must keep main's single_field_name=None so hooks see {'a': 1}. Fix: single-field from fields (len(fields) == 1, no var_kwargs) and that field must appear in the JSON schema
  • Why: Works on main and its hooks saw a different value on the PR head; disclosure doesn't make it acceptable (maintainer dsfaccini via manager). Regression 1 under 'Stop on the second regression'
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75
  • Supersedes: douwebot optional: sole SkipJsonSchema param unwraps

2026-11-13 · pre-push review 2 of 3 at f0dc723299665927a945a55a69332c98ed8d4d84 · iter -

2026-11-13 · pre-push review 2 of 3 at f0dc723299665927a945a55a69332c98ed8d4d84 · iter -

  • Decision: No code findings; 3 metadata findings remediated: body drops the sole-SkipJsonSchema disclosure, 'Why' names the JSON-schema-presence condition, Verification names only-hidden, douwebot thread gets a follow-up reply
  • Why: Reviewed tree 8344462e4fa5b271204cdcab81614d087c419869; follow-up ca3e3c208..e0932f4e4 + 219da569e..f0dc72329 plus callers; fresh claude -p opus from detached policy base 75ef1a9bd; both checkouts clean and unchanged after review; regression 1 entry supersedes the 'keep' entry
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · exempt delta f0dc72329..80e280b32: comment move · iter -

2026-11-13 · exempt delta 80e280b32..5eecf8406: test docstrings · iter -

2026-11-13 · CI flake at 5eecf8406: ipython timeout test · iter -

2026-11-13 · douwebot optionals at 5eecf8406: no push · iter -

  • Decision: Moved-comment wording (pre-existing 'info') acknowledged, rides with any later push; hook_unwrap_key docstring refuted as already accurate; both threads resolved
  • Why: Dispatch: an APPROVE with only optional findings passes once threads resolve; don't push just to clear such a nit
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323#discussion_r4559706709
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · step 7 second opinion: pydanty:review-lite · iter -

  • Decision: David picked pydanty:review-lite on 5eecf8406; partial coverage at pydanty's budget deadline is accepted
  • Why: It changes what output functions and hooks receive, and a regression surfaced late (maintainer dsfaccini via manager)
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · pydanty review-lite partial accepted · iter -

  • Decision: Accepted the partial review-lite run df_run_60f1e0ca40274678bef8 at 5eecf8406 (blocking 0, required 0, warnings 0; partial lanes review-sibling-consistency, single-arg-call-envelope); dismissed CHANGES_REQUESTED review 5886618693 with the tracked helper
  • Why: Maintainer dsfaccini via manager: every review-lite run has ended partial; #13312, #13325 and #13335 merged after one
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323#issuecomment-6844472717
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

2026-11-13 · pydanty wait ends on is-working removal · iter -

  • Decision: End every pydanty wait on the removal of pydanty:is-working after it was seen; never on a review-status marker in a review body
  • Why: The review-status marker sits on an issue comment created at pickup and edited in place; the review carries pydanty:review-gate, so the marker-count wait missed the 05:29:35Z finish
  • Source: https://github.com/pydantic/pydantic-ai/pull/13323#issuecomment-6844472717
  • Session: 73c111fd-f36f-4420-8fd0-918656eccc75

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.

https://claude.ai/code/session_01HhQjZ91ahZgmJ18vCRvYQW