
BAML Has a Free API: Define LLM Functions as Typed Interfaces
Prompt engineering is string manipulation. BAML makes it type-safe function definitions. What Is BAML? BAML (Basically A Made-up Language) is a DSL for defining LLM functions with typed inputs and outputs. You define the interface, BAML generates the client code and handles parsing, retries, and validation. // extract_resume.baml class Resume { name string email string skills string[] experience Experience[] } class Experience { company string role string years int } function ExtractResume(resume_text: string) -> Resume { client GPT4o prompt #" Extract structured data from this resume: {{ resume_text }} {{ ctx.output_format }} "# } # Generate client code npx @boundaryml/baml-cli generate // Auto-generated, fully typed client import { b } from ' ./baml_client ' const resume = await b . ExtractResume ( " John Doe, john@example.com, 5 years at Google as Staff Engineer, skills: Python, Go, K8s " ) console . log ( resume . name ) // "John Doe" — typed as string console . log ( resume . skil
Continue reading on Dev.to Python
Opens in a new tab


