Skip to content

pydantic_ai.models.typesafe

Setup

For details on how to set up authentication with this model, see model configuration for TypeSafe.

TypeSafeModelSettings

Bases: ModelSettings

Settings used for a TypeSafe model request.

Attributes

typesafe_tool_call_threshold

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

ToolCallProposed

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.

Attributes

tool_name

The tool Jev proposed.

Type: str Default: tool_name

probability

How likely Jev found the call, from 0 to 1.

Type: float Default: probability

TypeSafeModel

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 typeQuestionAnswer
boolyes or noTrue when Jev’s probability is at least 0.5
Literal[...] or Enum of stringspick onethe chosen option
float with ge=0 and le=1yes or noJev’s probability
whole numbers 0, 1, 2, … with a description per level in the schemascore against a rubricthe nearest level
list of a Literal or Enumone yes or no per optionthe options Jev said yes to
a nested model of theseits fields, named outer.innerthe model
Literal[...] or Enum, or Nonepick one, or none of thesethe 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.

Attributes

model_name

The model name.

Type: TypeSafeModelName

system

The system / model provider.

Type: str

Methods

__init__
def __init__(
    model_name: TypeSafeModelName,
    *,
    provider: Literal['typesafe'] | Provider[AsyncTypeSafeClient] = 'typesafe',
    profile: ModelProfileSpec | None = None,
    settings: ModelSettings | None = None,
)

Initialize a TypeSafe model.

Parameters

model_name : TypeSafeModelName

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.

TypeSafeStreamedResponse

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.

Methods

close_stream

@async

def close_stream() -> None

No live stream to close: the whole answer was in hand before the first event.

Returns

None

LatestTypeSafeModelNames

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']

TypeSafeModelName

Possible TypeSafe model names.

Default: str | LatestTypeSafeModelNames