TypeSafeModel. You give the agent a
Pydantic model as its output type, and each field becomes one question for Jev. Jev answers
all the questions in one request. TypeSafeModel turns each answer into a Python value of
the field’s type, and also returns Jev’s probabilities and confidence.
The agent triages messages sent to a bank’s support team. It asks two
questions about every message: what the message is about, and whether the customer reports
fraud. You end up with a Triage output type and a triage() function, which returns the
agent’s output for one message with Jev’s probabilities and confidence. You then decide in
code whether the fraud probability is high enough to send the message to the fraud team.
Setup
Run in Colab
Runs as published without an API key.
Python file
This page as one .py file, to run locally.
Open in playground
Edit one request and run it live. Needs a TypeSafe account.
uv run pydantic_ai_quickstart.py installs the dependencies for you.
The code replays saved answers, so it runs as published without an API key. To change a
request, set TYPESAFE_API_KEY; in Colab, add it in the Secrets panel.
The numbers below came from jev-1.14.0 on 2026-11-25.
Write the questions as a type
Pydantic AI builds the Jev request from your types and from the message you pass to the agent:
Pydantic AI sends each question’s instructions as a JSON object (see structured
instructions). The keys
field, question,
and goal are names Pydantic AI chose. They aren’t part of the TypeSafe API.
The field type sets the question type:
The state holds the text the questions are about, plus any facts that help answer them.
Pydantic AI builds it from the message you pass to the agent. Put any facts the questions
need, such as a refund policy, in the message. Keep them out of the class docstring and out
of the
instructions argument to Agent, because both are copied into every question.
State has more on keeping content apart
from questions.
topic is the Choice question and fraud is the Noul question, whose value is Jev’s
probability of yes.
A bool field would also be a Noul question, but Pydantic AI would turn the probability
into True or False at a threshold of 0.5. You can change that threshold with the
decision_boolean_threshold model setting.
A Score question needs an IntEnum that mixes in Pydantic AI’s UseEnumMemberDocstrings,
with a docstring under each level. Version 2.71.0 reads those docstrings from the source
file. A notebook has no source file, so in a notebook the question goes out without the
level descriptions. Put that enum in a .py file and import it.
Run the agent
Thetypesafe: prefix on the model name gives the agent a TypeSafeModel, which sends the
request to Jev. TypeSafeModel reads your key from TYPESAFE_API_KEY. With no key set, it
gets the placeholder from Setup, which is enough to replay the saved answers. Each message
goes to the agent as the user prompt.
To run the agent on one message, call triage(). It returns a dictionary with the agent’s
output and the response’s provider_details, which hold Jev’s confidence and
probabilities.
jev_request() builds the request Pydantic AI would send Jev, without calling the API. It
runs the agent with CaptureRequest, a model class that records the request instead of
sending it.
triage() returns plain JSON, so we validate its output into a Triage object to read
each field as a Python value. In provider_details:
- The
confidencekey holds a confidence score from 0 to 1 for each Choice question. A Noul question has no confidence score. Its probability of yes is thefraudvalue. - The
probabilitieskey holds Jev’s probability for every option of each Choice question. - The
scoreskey holds the answer to each Score question, so it is empty here.
Act on the probability in code
Jev’s answer forfraud is a probability, so you decide in code how high it has to be
before a message goes to the fraud team.
fraud value is 0.22. That leans no without ruling fraud out. The customer doesn’t
recognize the payment, which could be fraud or a subscription they forgot about.
A bool field would give you only True or False, decided by the same threshold for
every bool field. With the probability, you set a threshold for this one decision, based
on what a wrong answer costs. Missing fraud costs the bank more than checking a payment
that turns out to be fine, so we send any message with a fraud value of 0.3 or more to
the fraud team:
Open the request in the playground
To see the request Pydantic AI sends Jev for the last message, calljev_request(). Then
pass that request to make_playground_link() from cooksafe to get a TypeSafe playground
link. In the playground, you can run the request or change its questions.
Next steps
- Banking assistant: build a larger agent in which Jev picks one of 30 routes, asks the customer a follow-up question when it’s unsure, and passes money transfers to an LLM.
- The Pydantic AI TypeSafe docs cover
the provider, the model settings, and
FallbackModel, which switches to another model on API errors by default. - Primitives and confidence explain Noul, Choice, and Score, and how confidence is calculated.

