baml-codegen
by @killerapp
Use when generating BAML code for type-safe LLM extraction, classification, RAG, or agent workflows - creates complete .baml files with types, functions, clients, tests, and framework integrations from natural language requirements. Queries official BoundaryML repositories via MCP for real-time patterns. Supports multimodal inputs (images, audio), Python/TypeScript/Ruby/Go, 10+ frameworks, 50-70% token optimization, 95%+ compilation success.
clawhub install baml-codegenπ About This Skill
name: baml-codegen description: "Use when generating BAML code for type-safe LLM extraction, classification, RAG, or agent workflows - creates complete .baml files with types, functions, clients, tests, and framework integrations from natural language requirements. Queries official BoundaryML repositories via MCP for real-time patterns. Supports multimodal inputs (images, audio), Python/TypeScript/Ruby/Go, 10+ frameworks, 50-70% token optimization, 95%+ compilation success." license: "Apache-2.0" compatibility: "Requires MCP servers: baml_Docs (required), baml_Examples (optional). Works offline with 80% functionality using cached patterns."
BAML Code Generation
Generate type-safe LLM extraction code. Use when creating structured outputs, classification, RAG, or agent workflows.
Golden Rules
baml_client/ - 100% generated, overwritten on every baml-cli generate; check baml_src/generators.baml for output_type (python, typescript, ruby, go)baml_src/ - Source of truth for all BAML codebaml-cli generate after changes - Regenerates typed client code for target languagePhilosophy (TL;DR)
.baml β generate native code (Python/TypeScript/Ruby/Go), no runtime dependencybaml-cli test to iterateWorkflow
Analyze β Pattern Match (MCP) β Validate β Generate β Test β Deliver
β [IF ERRORS] Error Recovery (MCP) β Retry
BAML Syntax
| Element | Example |
|---------|---------|
| Class | class Invoice { total float @description("Amount") @assert(this > 0) @alias("amt") } |
| Enum | enum Category { Tech @alias("technology") @description("Tech sector"), Finance, Other } |
| Function | function Extract(text: string, img: image?) -> Invoice { client GPT5 prompt #"{{ text }} {{ img }} {{ ctx.output_format }}"# } |
| Client | client |
| Fallback | client |
Types
string, int, float, bool | Multimodal: image, audioType[] (array), Type? (optional), map (key-value)Type1 | Type2 (union), nested classes@description("..."), @assert(condition), @alias("json_name"), @check(name, condition)Providers
openai, anthropic, gemini, vertex, bedrock, ollama + any OpenAI-compatible via openai-generic
Pattern Categories
| Pattern | Use Case | Model | Framework Markers | |---------|----------|-------|-------------------| | Extraction | Unstructured β structured | GPT-5 | fastapi, next.js | | Classification | Categorization | GPT-5-mini | any | | RAG | Answers with citations | GPT-5 | langgraph | | Agents | Multi-step reasoning | GPT-5 | langgraph | | Vision | Image/audio data extraction | GPT-5-Vision | multimodal |
Resilience
retry_policy Exp { max_retries 3 strategy { type exponential_backoff } }[FastCheap, SlowReliable] for cost/reliability tradeoffMCP Indicators
Output Artifacts
1. BAML Code - Complete .baml files (types, functions, clients, retry_policy)
2. Tests - pytest/Jest with 100% function coverage
3. Integration - Framework-specific client code (LangGraph nodes, FastAPI endpoints, Next.js API routes)
4. Metadata - Pattern used, token count, cost estimate