Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Imperative frameworks (LangChain, LlamaIndex) make you write the prompt and wire each step; declarative frameworks (DSPy, BAML) make you declare a signature and a metric and let a compiler choose prompts and exemplars.
Imagine two cooking shows. In the first, the chef hands you a recipe step by step: chop the onion, sauté at medium, add salt at minute three. You can stop at any step and inspect what is in the pan. In the second, you tell the kitchen, 'I want a dish that scores nine out of ten on this taste test,' and a robotic chef tries combinations against your taste-test rubric until it finds the best one. You do not write the recipe. You write the scoring rubric. The first show is imperative cooking; the second is declarative cooking. Both produce dinner; they ask you for very different artefacts.
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.
5 minutes: who owns the prompt, why optimizer-selected exemplars are the tell, and when production stacks mix both paradigms.
| Aspect | Imperative (LangChain, LlamaIndex) | Declarative (DSPy, BAML) |
|---|---|---|
| Developer writes | The prompt + the wiring | The signature + the metric |
| Few-shot exemplars | Hand-picked | Optimizer-selected from labelled data |
| Mental model | Plumbing / Runnable composition | PyTorch-style program + optimizer + metric |
| Step-level debuggability | First-class. Every Runnable is inspectable | Limited. Compiled prompt is the artefact |
| Model migration cost | Re-tune prompts per provider quirk | Re-compile against the new model |
| Best fit | Orchestration, RAG plumbing, agents | Prompt-sensitive cores with labelled data |
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.
Calling DSPy 'just another prompting library' and missing that the load-bearing object is the compiler that searches for prompts and exemplars against a metric.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.