pydantic_ai.models.typesafe
For details on how to set up authentication with this model, see model configuration for TypeSafe.
Bases: ModelSettings
Settings used for a TypeSafe model request.
How likely Jev has to find a tool call before it is proposed, from 0 to 1. Default: 0.6.
With tools attached, one more question asks which tool the text calls for, the output tool among them. A tool
picked below this probability is a lean, and the output is filled as usual; one at or above it is raised as
ToolCallProposed for a model behind Jev to call. At 0.6, on
labelled support tickets, Jev’s picks agree with a frontier model as often as two frontier models agree with each
other; higher hands off less, and is right more often when it does. Tune it on labelled examples of your own.
Type: float
Bases: ModelAPIError
Jev found that the text calls for a tool, which it cannot call itself.
A ModelAPIError, so a
FallbackModel with a language model behind Jev hands it the
whole step by default, tools and all, and only the requests Jev hands off cost a language model call.
The tool Jev proposed.
Type: str Default: tool_name
How likely Jev found the call, from 0 to 1.
Type: float Default: probability
Bases: Model[AsyncTypeSafeClient]
A model that fills a structured output_type with one request to a TypeSafe Jev model.
Jev does not generate text. It answers typed questions about a text, each with a confidence. This model turns the output type’s fields into those questions and the user prompt into the text, so an agent whose job is to classify runs on it like on any other model:
from typing import Literal
from pydantic import BaseModel, Field
from pydantic_ai import Agent
class Handling(BaseModel):
verdict: Literal['run', 'reject', 'ask'] = Field(description='How to handle this command.')
irreversible: bool = Field(description='Would running this destroy data or leak secrets?')
agent = Agent('typesafe:jev-latest', output_type=Handling)
...
Each field is one question, all sent in one request:
| Field type | Question | Answer |
|---|---|---|
bool | yes or no | True when Jev’s probability is at least 0.5 |
Literal[...] or Enum of strings | pick one | the chosen option |
float with ge=0 and le=1 | yes or no | Jev’s probability |
| whole numbers 0, 1, 2, … with a description per level in the schema | score against a rubric | the nearest level |
list of a Literal or Enum | one yes or no per option | the options Jev said yes to |
| a nested model of these | its fields, named outer.inner | the model |
Literal[...] or Enum, or None | pick one, or none of these | the option, or None |
The field description is the question. The output type’s docstring and the agent’s instructions go along
as context. An option is described by a description on its value in the schema, and by its name without one.
A bare bool, Literal or float output has no field to describe, so there the agent’s instructions are the
question.
Confidence per field, from 0 for undecided to 1, is in
ModelResponse.provider_details under confidence,
the full distribution of each pick-one and rubric field under probabilities, and each rubric field’s
unrounded position along its levels under scores.
The latest user prompt is the text Jev judges, and is the whole state on its own. Everything before it in
the message history, from any model, goes along beside it as history: user prompts, answers, tool calls
and their results, and retry prompts.
Jev cannot write a tool’s arguments, but it can tell which tool the text calls for. With tools attached, one
more question asks which, the output type first among the options, described by its docstring or the agent’s
instructions. A tool that takes no arguments, or an output function that takes nothing but the run context,
is called on Jev’s pick, so it can run a loop of such tools and hand a run off to an output function on its
own. A tool with arguments, picked at or above
typesafe_tool_call_threshold, is raised as ToolCallProposed,
which a FallbackModel with a language model behind Jev hands
that model, tools and all.
Jev answers in one piece, so a streamed run gets the whole answer as one event rather than failing.
Anything else Jev cannot do is refused with a UserError before a
request is sent: text output, other field types, native tools, and files in the prompt or history.
Sampling settings like temperature do not apply and are ignored. timeout, extra_headers and
extra_body are forwarded.
Apart from __init__, all methods are private or match those of the base class.
The model name.
Type: TypeSafeModelName
The system / model provider.
Type: str
def __init__(
model_name: TypeSafeModelName,
*,
provider: Literal['typesafe'] | Provider[AsyncTypeSafeClient] = 'typesafe',
profile: ModelProfileSpec | None = None,
settings: ModelSettings | None = None,
)
Initialize a TypeSafe model.
The name of the TypeSafe model to use, such as jev-latest.
provider : Literal[‘typesafe’] | Provider[AsyncTypeSafeClient] Default: 'typesafe'
The provider to use for authentication and API access. Can be either the string
‘typesafe’ or an instance of Provider[AsyncTypeSafeClient].
profile : ModelProfileSpec | None Default: None
The model profile to use. Defaults to a profile picked by the provider based on the model name.
settings : ModelSettings | None Default: None
Model-specific settings that will be used as defaults for this model.
Bases: StreamedResponse
A whole answer from Jev as a stream of one event, so that a streamed run works on a model that cannot stream.
@async
def close_stream() -> None
No live stream to close: the whole answer was in hand before the first event.
TypeSafe aliases, which move when a release ships. jev-preview runs ahead of jev-latest when there is a
preview build. A versioned id such as jev-1.13.0 is accepted too, and is what to use once a confidence
threshold has been tuned against one. https://docs.typesafe.ai/models
Default: Literal['jev-latest', 'jev-preview']
Possible TypeSafe model names.
Default: str | LatestTypeSafeModelNames