Expand description
Type surface of submilli:llm.
call and batch are declared generic, and that generic is only sound
because the typechecker intercepts it. The typed forms are not a second
signature: they are a rewrite. A generic call<T> reaching the ordinary
generic-call lowering would set return_cast, which codegen emits as a Wasm
representation cast rather than a structural check, so a response that
ignored the schema would arrive statically typed and never validated. So the
typechecker matches the symbol by mangled name and rewrites the call into a
checked Cast instead — the contract submilli:session’s get carries.
The declaration and that interception are a matched pair, and a generic
declaration without the interception is the unsound half on its own, which
is why the generics landed together with
checked_llm_call rather than ahead of it.
is_checked_call is the hook that interception matches on.
T defaults to Completion (or Completion[] for batch) rather than to
unknown: the untyped call keeps its envelope, carrying ok/text/
reason, while the typed form trades that envelope for the checked value —
the same trade session.get<T> makes. That is why T appears only in the
return type here and is never inferable from an argument.
The trailing schema parameter is likewise not surface a program writes. It
defaults to undefined, and the typed lowering fills it with the JSON Schema
emitted from T at compile time — the way McpCall passes its server and
tool as constants. Passing it by hand changes only what the provider is
asked for; the structural check lives in the synthetic Cast, not in the
host fn, so a hand-passed schema buys no verification.
Functions§
- is_
checked_ batch - Whether
mangledis the single-prompt checked read, as opposed to the batch. The two lower the same way but differ in what a bare call returns —CompletionagainstCompletion[]— so the interception needs to tell them apart to pick the untyped default. - is_
checked_ call - Whether
mangledis one of this package’s checked reads. Matching the package-export mangled name rather than a receiver name is what makes the typechecker’s rewrite independent of how the symbol was imported —llm.call,models.callunder an aliased namespace import, and a named-importcallall carry this name, while a user’s ownllmbinding never can. - package_
declaration - untyped_
result_ type - What
Tbinds to when the program wrote no type argument, which keeps the untyped call’s pre-generic meaning: theCompletionenvelope forcall, and one per prompt forbatch. Unlikesession.get, the default is notunknown— an untypedllm.callis not an unchecked read, it is a different and fully-typed result.