IN THIS BREAKDOWN · 10 SECTIONS
You can read 18% of this breakdown.
The paper in one minute
Neural networks became easy to train once automatic differentiation made backpropagation turnkey: define the computation, call backward(), step the optimizer. Mert Yuksekgonul, James Zou and colleagues at Stanford asked what the equivalent would be for systems built from LLM calls and tools, where nothing is differentiable. Their answer, TextGrad, uses "gradients" that are critiques written by an LLM.
Take the simplest system: a prompt produces a prediction, and an evaluator LLM judges the prediction. In the backward pass, an LLM reads the evaluation and writes feedback on the prediction ("this can be improved by..."). Then, given the prompt, the prediction and that feedback, it writes feedback on the prompt. Textual gradient descent asks an LLM to rewrite the prompt using the feedback. In a larger graph the same happens edge by edge: each variable collects critiques from everywhere it was used, at one extra LLM call per edge per iteration.
The framework copies PyTorch's shape: tg.Variable with requires_grad, a loss, loss.backward(), optimizer.step(), minibatches through tg.sum, plus analogs of momentum (the optimizer sees earlier versions) and constraints (format rules written in English). The objective can be an LLM judge, unit-test results or a simulator's output.
The paper applies it to two kinds of problem. Instance optimization improves one artifact: code for LeetCode Hard problems, answers to GPQA and MMLU questions, small molecules scored by docking and druglikeness, and radiotherapy plans for five prostate cancer patients. Prompt optimization improves one prompt for a task: GPT-3.5 Turbo prompts for Object Counting, Word Sorting and GSM8K, with GPT-4o writing the feedback.
Research notes: the problem, approach and results
LeetCode Hard completion with GPT-4o after TextGrad, against 31% with Reflexion and 26% zero-shot (5 seeds)
GPQA accuracy with GPT-4o, using three refinement passes and a majority vote over the four answers
GSM8K accuracy for GPT-3.5 Turbo after 12 prompt updates with batches of 3, the same as DSPy's 8-shot prompt
Compound AI systems chain LLM calls, tools and simulators, none of them differentiable. They were tuned by hand, prompt by prompt, with no general way to say which component should change and how.
Represent the system as a graph of variables (prompts, code, answers, molecules). An LLM writes natural-language feedback on the output, then on each upstream variable given the feedback below it, and an optimizer LLM rewrites each variable. The API mirrors PyTorch.
GPT-4o's LeetCode Hard completion rose from 26% to 36%, GPQA accuracy from 51% to 55%, and GPT-3.5 prompts tuned with GPT-4o feedback matched or beat DSPy few-shot prompts. Molecule and radiotherapy results are in-silico proofs of concept.
Why it matters to an FDE
The useful idea is credit assignment. When a customer's four-step pipeline gives a bad answer, the question is which step to change. TextGrad's backward pass asks an LLM that at every edge, which is a structured way to turn one failed output into feedback on the retrieval prompt, the drafting prompt or the formatting step.
Use a stronger model to tune a cheaper one. The prompt experiments used GPT-4o to write feedback for GPT-3.5 Turbo's prompt. Paying once for a strong model's critique and then serving the cheap model is a sound cost pattern.
Count the calls. Every iteration adds one critique call per edge, plus an update call per variable, plus the evaluator. On a long pipeline, that is several times the cost of a forward pass.
Demand a compute-matched baseline. Refining an answer three times and voting over four versions spends four answers' worth of compute. The fair comparison is four independent answers, voted. The paper does not report it, and our simulation below shows why it matters.
Gate every update on held-out data. In the prompt experiments, TextGrad kept a new prompt only if validation accuracy improved. Without that gate, an LLM's confident critique can make things worse.
Understand the mechanism. Try it on a real problem.
Unlock this breakdown and 99 more papers.
Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.
6 months · One payment · No auto-renewal
- ◇1 architecture diagram
- </>1 runnable code experiment
- ▦2 results tables
- ?5 interview questions with answers
- 03Key takeaways
The operators, the two problem types, the results, and misreadings to avoid
Free account - 04How it works
The forward and backward passes, the optimizer, batching, constraints, and each application's loss
Premium - 05The numbers that matter
The size of each gain, the inconsistencies, and what is compute-matched and what is not
Premium - 06Try it yourself
Is a refinement gain from the critique or from voting? A simulation with a compute-matched baseline
Premium - 07Where it breaks
Where textual gradients mislead, cost too much, or are not yet evidence
Premium - 08Using it on a deployment
Applying backward critiques to a customer pipeline with gates and budgets
Premium - 09Interview angles
Five questions this paper prepares you for, with answer hints
Premium - 10Read next
Where to go from here on this site
Premium
