How does a declarative LLM framework differ from an imperative one in what the developer actually writes?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Declarative tools like DSPy and BAML compile prompts from a signature plus a metric; imperative tools like LangChain and LlamaIndex execute the prompts and steps the developer wrote.
Picture two cooks asked to make the perfect omelet. The first cook writes the recipe themselves, three eggs, this much butter, sixty seconds on each side, and follows it exactly. If the omelet is bad, they edit the recipe and try again. The second cook only writes down what counts as a great omelet and hands a robot a basket of eggs. The robot tries hundreds of recipes, keeps the ones the judge liked best, and serves the winner. Cook one knows every detail of how the omelet was made. Cook two never sees the recipe but the omelet usually scores higher. Different tradeoffs, both valid.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 minutes: the two families, who writes the prompt, why DSPy compiles, why BAML codegens, when teams mix the two.
| Axis | Imperative (LangChain, LlamaIndex) | Declarative (DSPy, BAML) |
|---|---|---|
| What developer writes | Prompts plus chain code | Signature or schema plus metric |
| What model receives | What the developer wrote | What the compiler generated |
| Optimization | Manual prompt iteration | Automatic search against a metric or codegen from schema |
| Debuggability | Every step visible | Final prompt is a compiler artifact |
| Best fit | Moving target, no labels, deep custom control | Stable task, labeled data, want prompt to keep improving |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating DSPy as just another chain builder, then being confused that you never get to write the actual prompt text the model sees.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.