Deprecate `fallback_model` in favor of `fallback_subagent_model` on `ImageGeneration` and `XSearch`
This pull request was posted by Claude Code using claude-fable-5-1 on behalf of David.
ImageGeneration gained a second fallback in #5357: local= now takes a direct image model, alongside the existing fallback_model=. With two of them, fallback_model no longer says which one it configures — and because its type is Model | KnownModelName | str | callable, fallback_model='openai:gpt-image-2' type-checks even though the subagent path cannot run an image-only model. Only names listed in the hand-maintained _IMAGE_ONLY_MODELS dict are caught; anything else reaches the provider as a model-not-found error.
This renames the field to fallback_subagent_model on ImageGeneration and XSearch, and deprecates fallback_model.
- Closes #8061
Naming
fallback says when the model is used — only when the agent's own model has no native support for the tool. subagent says how — an extra agent run, as against the local= tool that ImageGeneration also takes a direct image model for. Both halves are load-bearing, so the name keeps both.
Every class in pydantic_ai_slim that carries this value, and the reading that has to hold for each:
| Class | Carries it as | Used only when native is unavailable | Used only through a subagent |
|---|---|---|---|
capabilities.ImageGeneration | fallback_subagent_model | yes — _default_local() builds the tool as local, and NativeOrLocalTool.get_toolset stamps unless_native=ImageGenerationTool.kind on it, so any model with native image generation drops it (native=False means there is no native tool at all) | yes — common_tools.image_generation.image_generation_tool wraps it in ImageGenerationSubagentTool, whose __call__ runs an Agent |
capabilities.XSearch | fallback_subagent_model | yes — same _default_local() / unless_native=XSearchTool.kind path | yes — common_tools.x_search.x_search_tool → XSearchSubagentTool.__call__ runs an Agent |
common_tools.image_generation.ImageGenerationSubagentTool | model | n/a — the class is only ever constructed from the field above | yes — it is the subagent |
common_tools.x_search.XSearchSubagentTool | model | n/a — same | yes |
No other capability has such a field: WebSearch, WebFetch and MCP are the other NativeOrLocalTool subclasses and none of them falls back to a subagent. models.FallbackModel(*fallback_models) is an unrelated symbol that shares the word.
Backward compatibility
fallback_model= keeps working unchanged and emits PydanticAIDeprecationWarning; so do reads and writes of .fallback_model, which is now a deprecated property over the new field. Passing both names raises UserError rather than picking one silently. Every deprecated path carries a TODO(v3): remove marker.
fallback_model also stays in ImageGeneration.from_spec and XSearch.__init__, and so in the published capability spec schema. That is deliberate: _spec.py::build_schema_types builds each capability's TypedDict from that signature with extra='forbid', so removing the key would make a spec written against the old name fail validation outright instead of deprecating it. The schema snapshot in tests/test_capability_spec.py therefore gains fallback_subagent_model beside the existing fallback_model on both capabilities.
The deprecated name is an __init__/from_spec parameter and a property, never an instance attribute: capabilities/_merge.py::merge_capability_fields refuses any non-underscore attribute that no dataclass field declares, so storing it would break combine.
Stacked on #5357
The branch is cut from #5357's head (b119d3841), because that PR is what rewrites ImageGeneration, its docs and its tests. Until #5357 merges, the diff here also shows #5357's commits; once it does, this reduces to the single rename commit plus a merge of main.
Deliberate skips
- The public type aliases
ImageGenerationFallbackModel,ImageGenerationFallbackModelFunc,XSearchFallbackModelandXSearchFallbackModelFunckeep their names. They are exported symbols, so renaming them is a second deprecation surface for no user-visible gain; only their docstrings changed, to point at the new field. _check_image_only_modeland_IMAGE_ONLY_MODELSincommon_tools/image_generation.pyare unchanged apart from the field name in their error message. The name is what carries the meaning now; the dict stays as a courtesy.- No
docs/changelog.mdentry: a deprecation is not a breaking change under the version policy, and the PR title carries it into the release notes. - The spec schema advertises both keys with identical types and no
deprecated: truemarker. Marking one would mean wrapping its annotation inAnnotated[..., Field(deprecated=True)], and_spec.py::filter_serializable_typedoes not recurse throughAnnotated— I checked: the wrappedXSearch.__init__annotation keeps itsCallablearm instead of having it stripped. Teaching it to recurse changes shared spec machinery for every capability, so the guidance lives in the docs instead. - The snapshot literal in
tests/test_capability_spec.pykeepsfallback_modelnext tofallback_subagent_model, while the generated schema puts it last (it is the last parameter). Snapshot comparison is dict equality, and JSON object key order carries no meaning; keeping the two model keys adjacent reads better than mirroring the emitted order. - The four deprecation tests are near-duplicates across
tests/test_capability_image_generation.pyandtests/test_capability_native_or_local.pyrather than parametrized over both capabilities, because #7304 split the capability tests per capability and a shared parametrization would putXSearchbehavior in the image-generation file.
Checklist
- Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.