Natural-Language Optimizer Constraints

Append hard format or domain rules as natural-language constraint blocks to the textual optimizer so updates must satisfy them.

When running textual gradient descent, soft critiques alone may break output contracts. TextGrad injects constraints as natural-language postfixes inside <CONSTRAINTS>…</CONSTRAINTS> on the optimizer prompt (e.g. force a final line Answer: $LETTER with LETTER ∈ {A,B,C,D}). The API attaches constraint strings to the optimizer alongside parameters.

Use this for harness invariants — answer formats, schema tags, safety refusals — that optimization variable role descriptions alone do not enforce. Instruction-tuned models follow simple constraints reliably; stacking too many drops compliance — prefer a short hard set over a laundry list. Still verify with offline prompt evaluation; LLM optimizers can ignore constraints under pressure. Pair with critique–optimizer separation so constraints live on the rewrite step, not the critique engine.


Sources

  • TextGrad (Yuksekgonul et al.), ch. 3 §3.1; ch. 7