"Schema engineering > prompt engineering" — this is BAML's key insight. The types you define drive the prompt AND the parsing.
The ? on fields means "optional"—and BAML tells the model this. See how {{ ctx.output_format }} expands into detailed schema instructions.
class ContactInfo {
name string
email string?
phone string?
company string?
}
function ExtractContact(text: string) -> ContactInfo {
client "openai/gpt-4o-mini"
prompt #"
Extract contact information from:
{{ text }}
{{ ctx.output_format }}
"#
}