Description
When using the capture_run_messages context manager - user errors also show an internal error from the library.
Exceptions occur inside an internal exception handler in pydanticAI and will include something like..
...
LookupError: <ContextVar name='var' at 0x10635a020>
During handling of the above exception, another exception occurred:
...
<user exception>
Which is confusing and unnecessary
example for reproduction
from pydantic_ai import (
Agent,
capture_run_messages,
)
agent = Agent('openai:gpt-4o')
with capture_run_messages() as messages:
result = agent.run_sync('How are you?')
1 / 0
print(messages)
References
From the docs - https://ai.pydantic.dev/agents/#model-errors