Skip to main content
ProTeGi (Prompt optimization with Textual Gradients) systematically improves prompts by identifying failure patterns, generating targeted critiques, and applying specific fixes. It uses beam search to maintain multiple candidate prompts and progressively refines them.

When to Use ProTeGi

✅ Best For

  • Debugging specific failure modes
  • Systematic error correction
  • Tasks with clear failure patterns
  • Iterative refinement workflows

❌ Not Ideal For

  • Quick experiments (multi-stage process)
  • Tasks where failures are random
  • Very small datasets
  • Budget-constrained projects

How It Works

ProTeGi follows a structured expansion and selection process:
1

Identify Failures

Run current prompts and identify examples with low scores
2

Generate Critiques

Teacher model analyzes failures and generates multiple specific critiques (“gradients”)
3

Apply Improvements

For each critique, generate improved prompt variations
4

Beam Selection

Evaluate all candidates and keep top N prompts
5

Iterate

Repeat expansion from the best performing prompts
ProTeGi maintains a “beam” of candidate prompts throughout optimization, preventing premature convergence to local optima.

Basic Usage


Underlying Research

ProTeGi introduces a novel, gradient-inspired approach to prompt optimization, adapting concepts from numerical optimization to natural language.

Configuration Parameters

Core Parameters

LiteLLMGenerator
required
Powerful model for generating critiques and improved prompts. Recommended: gpt-4o, claude-3-opus.
int
default:"4"
Number of distinct critiques to generate for each prompt. More gradients = more diverse improvement directions.
int
default:"4"
Number of failed examples shown to teacher when generating each critique. Higher = more context but more expensive.
int
default:"1"
Number of new prompts to generate from each critique. Set to 2-3 for more exploration.
int
default:"4"
Number of top-performing prompts to keep each round. Larger beam = more diversity but slower.

**Optimization Parameters