Declare named, typed operations with expression or model-backed bodies.
Syntax
return-number.bamlfunction return_number(value: int) -> int {
value
}function return_number(value: int) -> int {
value
}| Part | Required | Purpose |
|---|---|---|
| Function name | Yes | Names the operation that callers invoke. |
| Parameters | Yes | Declares the named, typed inputs; the list may be empty. |
| Return type | Yes | Defines the result expected by BAML and generated clients. |
| Body | Yes | Computes the result or declares a client and prompt. |
Parameters
Parameters are named and typed. Separate multiple parameters with commas. In BAML, pass required arguments in declaration order or by name. Parameters with defaults are passed by name. Generated SDKs map those arguments to the host language’s calling conventions.
typed-parameters.bamlfunction format_summary(title: string, body: string) -> string {
title + ": " + body
}function format_summary(title: string, body: string) -> string {
title + ": " + body
}Function bodies
Expression functions evaluate ordinary BAML expressions. Model-backed functions declare a client and prompt. Both forms must satisfy the declared return type.
| Body kind | Use it for |
|---|---|
| Expression | Deterministic transforms, branching, and composition. |
| Client + prompt | Typed operations whose result is produced by a model. |
Examples
See a function in context in Classify support tickets. For available chapters, see the book’s table of contents.