Yashotantra Academy logo

4 · DSPy & Guardrails

4. Programmatic Optimization with DSPy & Defense Against Injection

Compiling prompt signatures with teleprompters, metric evaluators, and sanitizing untrusted inputs.

10 min read · 2 MCQs

DSPy: Moving from String Hacks to Code

DSPy replaces brittle string-concatenated prompts with declarative modules and signatures. Teleprompter optimizers (BootstrapFewShot, MIPRO) automatically generate, test, and tune optimal prompts against evaluation metrics.

Prompt Injection & Delimiter Sanitization

Untrusted user inputs and web scrapes must be isolated using strict XML tags (`<user_data>...</user_data>`) and verified by semantic safety guardrails. System instructions must never trust payload content as actionable commands.

Chapter quiz

2 questions · pass mark 75%
  1. 1. How does DSPy differ from manual prompt engineering?

  2. 2. What is indirect prompt injection?