Sometimes you don't know your schema until runtime—user-configured forms, database-driven fields, or plugin systems.@@dynamic and TypeBuilder let you add properties on the fly.
Mark a class with @@dynamic in BAML, then use TypeBuilder in your code to add fields before calling the function.
// BAML Definition - mark class as @@dynamic
class FormField @@dynamic {
label string
value string
}
function ExtractForm(image: image) -> FormField[] {
client "openai/gpt-4o-mini"
prompt #"
Extract all form fields from this image:
{{ image }}
{{ ctx.output_format }}
"#
}