TypeSafeClassifier class sends your questions to Jev,
and Jev returns each answer with its probabilities and a confidence. This page uses the
Python library; the integration is also in the TypeScript LangChain library.
We ask one Choice question about a tool call that a shop’s AI support assistant proposes.
You end up with a decide() function that returns Jev’s response for one proposed tool
call. An outcome() function turns that response into run, review, or refuse, and
returns review for any answer whose confidence is under a threshold you set. The
Tool-call safety gate cookbook asks the same question
before every tool call an agent makes.
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 langchain_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-24.
Write the question
Write each question with a type from LangChain’slangchain_core.decisions module, and
give it an id you choose. Each type becomes the System One question of the same name:
We ask one
Choice question. Its instructions hold the shop’s policy: what the assistant
may do without approval, what needs a person’s approval first, and what the assistant must
not do. Each criteria entry is one label, run, review, or refuse, with a
description of when it applies.
Build the state
The state is what Jev reads: a JSON object with the customer’s account, the conversation, and the proposed tool call. Jev knows only what the state says, so we include the account to show that orderO-7790 is this customer’s. Each message here is a plain object with a
role and a content. The state can also be a string or LangChain
messages, which the classifier
converts for you.
Ask Jev
We build one classifier forjev-1.14.0 and reuse it for every request. The classifier
reads your API key from TYPESAFE_API_KEY. With no key set, it gets the placeholder key
cache-only. That is enough to build the classifier, and no request is sent when every
answer is already in the cache.
We pass the state and the questions together to the classifier’s invoke method and get
back a ClassifierResponse. In your own code, that call is all you need. On this page,
ask_jev() wraps the call in a cache from cooksafe, so that the page can replay saved
answers. The cache reuses an answer only when the state, the question, and the model are
all unchanged. If you change any of them, the request goes to Jev. In decide() we call
ask_jev() with a state and the action question, and turn the stored JSON back into a
ClassifierResponse.
action. On the response
object, the answers are grouped by type in nouls, choices, scores, and boxes, so we
read this one from response.choices["action"]. Its choice field is the label with the
highest probability. Here that is review: the customer asked for the refund, and 450 is
over the 100 that the policy allows without approval. The probabilities field has one
entry per label. The confidence field, from 0 to 1, says how concentrated those
probabilities are. It is not the probability of the chosen label; see
confidence.
Act on the answer in code
We return Jev’s label, unless the answer’s confidence is under the threshold. Then we returnreview, so that a person looks at the tool call:
decide() once per
state, so each answer goes into the cache. The classifier’s batch method would save no
requests, because it also sends one request per state.
run. In the second, the customer asked where the order was, not for a refund, so Jev
picks refuse. In the third, the 89 refund is 100 or less, but O-8102 is not one of this
customer’s orders, so Jev picks refuse again. Jev can tell that only because the account
is in the state. The Tool-call safety
gate cookbook asks about one
tool call with the account in the state and without it.
Open the request in the playground
We pass the same state and questions tomake_playground_link() from cooksafe, which
returns a link to the TypeSafe playground. The link opens the 450 refund on O-7790 with
its question. Edit either one there and ask Jev again.
Next steps
- Tool-call safety gate: check every tool call an agent makes, first with LangChain’s built-in middleware, then with a custom middleware, and grade both on labeled tool calls.
- The LangChain TypeSafe docs cover the classifier, LangChain messages as state, tracing in LangSmith, and the two built-in middleware classes that use the classifier.
- Primitives and confidence explain the question types and how confidence is calculated.

