Pydantic AI shipped two releases back to back this week: v2.75.0 on 25 November and v2.76.0 on 26 November. Most of the changes are small, but three of them matter to anyone running agents in production: empty or broken model responses now trigger your fallback models, requests to retiring Gemini 2.5 models raise a warning, and each tool can now decide how much of its activity a chat UI is allowed to see.
This guide walks through all three with code you can run locally. None of the examples need an API key, because they use Pydantic AI’s built-in FunctionModel and TestModel instead of a real provider.
Install or upgrade
pip install -U "pydantic-ai-slim==2.76.0"
# or, with every provider extra
pip install -U "pydantic-ai==2.76.0"
Check the version you’re actually importing:
import pydantic_ai
print(pydantic_ai.__version__) # 2.76.0
1. Empty and invalid responses now trigger fallbacks
Sometimes a provider returns HTTP 200 with nothing useful inside: a stream that ends before its first event, or a completion with an empty choices list. Before 2.75, Pydantic AI raised a plain UnexpectedModelBehavior in those cases. FallbackModel only switches models on ModelAPIError by default, so a glitch like this ended the run even when you had a backup model configured.
In v2.75.0 these cases raise two new exceptions:
ModelEmptyResponseError: the provider answered but sent no response. The docstring calls this “often a transient glitch”, so a retry or another model may well succeed.ModelInvalidResponseError: the provider answered, but the response couldn’t be used (for example, it doesn’t match the API’s schema). Retrying the same model often fails the same way, but another provider may handle it.
Both are subclasses of ModelAPIError, so FallbackModel and the ModelFallback capability fall back on them automatically. They also still subclass UnexpectedModelBehavior, so existing except UnexpectedModelBehavior: blocks keep working.
Here is a self-contained demo. The first model simulates an empty answer and the second one picks up the request:
import warnings
from pydantic_ai import Agent, DeprecatedModelWarning
from pydantic_ai.exceptions import ModelEmptyResponseError
from pydantic_ai.messages import ModelResponse, TextPart
from pydantic_ai.models.fallback import FallbackModel
from pydantic_ai.models.function import AgentInfo, FunctionModel
# Fail fast in CI if any request targets a deprecated model
warnings.filterwarnings("error", category=DeprecatedModelWarning)
def flaky(messages, info: AgentInfo) -> ModelResponse:
# Stand-in for a provider that returns a successful but empty answer
raise ModelEmptyResponseError(model_name="flaky-model", message="no choices in response")
def backup(messages, info: AgentInfo) -> ModelResponse:
return ModelResponse(parts=[TextPart("Answer from the backup model")])
agent = Agent(FallbackModel(FunctionModel(flaky), FunctionModel(backup)))
result = agent.run_sync("Summarise today's deploy log")
print(result.output) # Answer from the backup model
In a real app, replace the two FunctionModels with your primary and backup models, passed as model objects or "provider:model-name" strings, primary first.
What to check in your code
If you have custom handling that catches UnexpectedModelBehavior and retries, some of those errors will now be handled by FallbackModel before your code ever sees them. That’s usually what you want. If you’d like to log them separately, catch ModelAPIError (the release notes point out that some adapters still raise a plain ModelAPIError for the same situation).
2. Deprecation warnings for Gemini 2.5 Pro and Flash
v2.76.0 adds a compatibility note you should know about before upgrading. Requests to gemini-2.5-pro or gemini-2.5-flash through GoogleModel or GoogleInteractionsModel now emit a DeprecatedModelWarning. It’s a UserWarning, which has two effects:
- In normal runs you’ll see the warning once per Python’s warning rules. It names the model, the retirement date, and the recommended replacement.
- If your test suite turns warnings into errors (for example
filterwarnings = errorinpytest.ini), any test that calls those models will now fail.
You have three options:
- Migrate to the replacement named in the warning. This is the right long-term fix.
- Silence the warning temporarily with a filter while you plan the migration:
import warnings
from pydantic_ai import DeprecatedModelWarning
warnings.filterwarnings("ignore", category=DeprecatedModelWarning)
- Turn off the deprecation for a single model by overriding its profile, as the release notes describe, with
profile={'deprecation': None}when you create the model.
The opposite also works well. Make the warning an error in CI (as in the fallback example above), so a deprecated model can’t sneak into production through a config change.
3. Per-tool ui_visibility for chat front ends
If you stream agent runs to a browser through one of Pydantic AI’s UI adapters (such as the AG-UI adapter), every tool call and its result were sent to the client by default. That’s fine for a weather tool, but not for a tool that returns internal notes or fraud scores.
v2.76.0 adds a ui_visibility option to each tool. The values are defined in pydantic_ai.messages:
| Value | What the client receives |
|---|---|
'public' |
The tool call and its result, in full |
'redacted' |
The call with its arguments, and a placeholder instead of the result |
'private' |
Neither the call nor the result |
When you leave it as None, the adapter’s default_ui_visibility applies, which is 'public'.
from pydantic_ai import Agent
from pydantic_ai.messages import ToolCallPart, ToolReturnPart
from pydantic_ai.models.test import TestModel
agent = Agent(TestModel(), instructions="Help support staff look up orders.")
@agent.tool_plain(ui_visibility="redacted")
def lookup_customer(customer_id: int) -> dict:
"""Return the customer's record, including internal notes."""
return {"id": customer_id, "email": "[email protected]", "risk_note": "manual review"}
@agent.tool_plain(ui_visibility="private")
def fraud_score(customer_id: int) -> float:
"""Internal fraud score. Never shown to the end user."""
return 0.12
result = agent.run_sync("Check customer 42")
for msg in result.all_messages():
for part in msg.parts:
if isinstance(part, (ToolCallPart, ToolReturnPart)):
print(type(part).__name__, part.tool_name, part.ui_visibility)
Running this prints each call and return part with its visibility stamped on it (redacted or private). The model still sees the full tool results. Only what the UI adapter forwards to the browser changes.
One caution: the parameter is typed as a Literal, but Python won’t stop you passing a typo like "hidden" at runtime. Run a type checker (Pyright, mypy or ty) over your agent code so mistakes get caught.
Other changes worth a look
The v2.76.0 notes list more changes. These are the ones most likely to affect you:
GoogleInteractionsModeladds stateless support for Google’s Interactions API.CodeMode(allow_final_output=True)lets sandboxed code submit the run’s final output directly.pydantic_ai.root_conversation_idis now recorded on spans of nested agent runs, so sub-agent cost rolls up to the outer conversation in your tracing tool.result.conversationkeeps every message a run adds, even when a capability trims the history mid-run.- The
FileSystemtool’sread_fileoffsetis now 1-indexed. If you pass offsets yourself, re-check them.
From v2.75.0, also note that instructions are now shared across a conversation’s requests rather than copied per request. Gemini’s thinking tokens are also counted as output in OpenAIChatModel usage, so your cost reports may shift slightly.
Upgrade checklist
- Pin
pydantic-ai==2.76.0in a branch and run your test suite. - Search for
gemini-2.5-proandgemini-2.5-flashand plan a migration. - Wrap your production model in
FallbackModelif you haven’t already. Empty responses now trigger it. - Add
ui_visibilityto any tool whose output shouldn’t reach the browser. - Check any code that passes
offsettoread_file.
Takeaway
This isn’t a headline release, but it fixes a real gap. Agents with a backup model now survive empty or garbled responses instead of failing, and you can keep sensitive tool output out of the browser with one keyword argument. Upgrade, fix whatever the new Gemini 2.5 warnings flag, and read the full notes for v2.76.0 and v2.75.0 before rolling out.
