Format("name"); the registry holds the
name, the semantic type the model is offered, and the function between them.
TransformSpec
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.
str
Description offered to the model. Defaults to
f"{semantic_type.__name__} data".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
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"
Description for the model.
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.
Related
- Transforms — the narrative version, including writing your own
- Semantic types — the shapes these transforms consume
- Protobuf types —
proto_jsonandfield_maskinputs