ai.FunctionSpec

One unit of model work, bound and unrun. Immutable; getters only.

Reference version

Signature

class ai.FunctionSpec<Out>

One unit of model work, bound and unrun. Immutable; getters only.

MyFunc@spec(args) calls the compiler-generated private MyFunc@spec companion. Streaming calls the separate private MyFunc@stream companion, whose return type carries the Out$stream schema. Neither companion is public.

Source:<builtin>/ai/spec.bamlbytes 42966621

Fields

spec_name

string

args

map<string, unknown>

Instance methods

function

arguments

(self) -> map<string, unknown>
function

build_request

(
self,
client: ai.Client | null = …
) -> baml.http.Request throws baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Builds the provider HTTP request shape for this spec without invoking the model. client overrides the spec's default; null uses the default.

function

call

<__effect_param_0>(
self,
client: ai.Client | null = …,
on_event: ((ai.events.Event) -> void throws __effect_param_0) | null = …
) -> Out throws baml.errors.InvalidArgument | baml.errors.Timeout | baml.errors.UnknownError | reflect.errors.CompilationError | ai.errors.Failure

Runs this bound spec through the default agent. client overrides the bound client; null keeps it. on_event observes the same journal events a direct LLM-function call reports.

function

client_id

(self) -> string
function

name

(self) -> string
function

output_type

(self) -> reflect.Type throws reflect.errors.CompilationError
function

parse

(self, json: string) -> Out throws baml.errors.ParseError

Parses an existing model reply using this spec's realized output type.