Write an LLM function in 10 lines

Ever had an LLM return malformed JSON? Or get a string when you wanted a structured object? BAML makes that impossible. Click Run to see the prompt preview and output.

Notice how {{ ctx.output_format }} expands into schema instructions, and the output is a typed enum value—not a string to parse.

main.baml
enum Sentiment {
  POSITIVE
  NEGATIVE
  NEUTRAL
}

function ClassifySentiment(text: string) -> Sentiment {
  client "openai/gpt-4o-mini"
  prompt #"
    Classify the sentiment of: {{ text }}
    {{ ctx.output_format }}
  "#
}
Click Run to see the rendered prompt