Skip to main content
A transform converts what the model wrote into what the wire wants. Fields opt in with Format("name"); the registry holds the name, the semantic type the model is offered, and the function between them.

TransformSpec

One registered transform.
str
The name written in a Format marker.
type
What the model sees for a field carrying this transform. Substituted into llm_schema() in place of the declared wire type.
Callable[[Any], Any]
Semantic value in, wire value out.
Optional[str]
Replaces the description of every field the transform is applied to, in what the model reads. Set it for an encoding, whose fields were described for the wire (“a base64url encoded string”). None when none was given, and then each field keeps its own description.

TransformRegistry

The registry itself. Its _transforms mapping is a class attribute, so registration is process-wide and a name registered twice is replaced.
Callable
Decorator form. Returns the function unchanged, so the transform stays callable on its own.
Optional[TransformSpec]
The spec, or None when nothing is registered under that name.
list[str]
Every registered name, sorted.
Any
Run the transform. A dict is coerced into the spec’s semantic_type first, which is what lets a model’s JSON object arrive where an EmailContent is expected. A transform registered against bare BaseModel — proto_json — is exempt, since coercing to a model with no fields would discard the payload.

register_transform

The non-decorator form, for registering a function you already have.
str
required
Unique name, as written in Format.
Type[Any]
required
The type the model is offered.
Callable[[Any], Any]
required
Semantic value in, wire value out.
Optional[str]
default:"None"
Replaces the description of every field the transform is applied to. Leave it out to keep each field’s own.

get_transform

TransformRegistry.get as a function. None when the name is unregistered — this is a lookup, not an assertion.

apply_transform

TransformRegistry.apply as a function. Raises TransformError when the name is unknown (the message lists what is registered), when the value does not validate as the semantic type, or when the transform function itself raises. You rarely call this: the executor applies transforms as part of building the request. Call it to test a transform of your own.

Built-in transforms

bytes and base64url encode identically. The separate name exists for readability against Google APIs whose schemas say bytes. rfc822_base64 builds multipart/alternative when bodyHtml is set alongside body, sends text/html when mimeType says so, and carries In-Reply-To and References through so a reply threads.