Skip to content

pydantic_ai.models.wrapper

WrapperModel

Bases: Model

Model which wraps another model.

Does nothing on its own, used as a base class.

Attributes

wrapped

The underlying model being wrapped.

Type: Model Default: infer_model(wrapped)

settings

Get the settings from the wrapped model.

Type: ModelSettings | None

serving_wrapper_scope

@async

def serving_wrapper_scope(wrapper: Model, borrowed: Model) -> AsyncGenerator[Model]

Enter wrapper, a capability’s wrapper around borrowed, around a request it serves.

borrowed isn’t entered or exited with it: its owner, like async with agent:, manages its lifecycle, and exiting it here could close an HTTP client another request is using. The exit is shielded from cancellation, so it finishes, and its return value is discarded, so it can’t suppress the request’s error. The cancel scope encloses the whole of it, so a cancel scope or task group the wrapper opens when entered is closed inside the same one.

Returns

AsyncGenerator[Model]