Skip to main content
Random Search is a gradient-free method that generates random variations of an initial prompt using a “teacher” LLM and selects the best-performing one. It’s a fast and straightforward way to explore different prompt phrasings and styles.

✅ Best For

  • Establishing a quick baseline
  • Simple tasks like summarization
  • Broad exploration of prompt space
  • Low computational budget

❌ Not Ideal For

  • Complex, nuanced tasks
  • Directed, efficient optimization
  • Tasks requiring structured prompts
  • Finding the absolute best prompt

How It Works

  1. Variation Generation: A teacher model creates a set number of diverse rewrites of your initial prompt.
  2. Evaluation: Each variation is tested against your evaluation dataset.
  3. Selection: The variation with the highest average score is chosen as the best prompt.
1

Initialize

Start with an initial prompt template.
2

Generate Variations

Use a teacher LLM to create diverse rewrites of the prompt.
3

Evaluate All Variations

Score each new prompt against the evaluation dataset.
4

Select Best

Choose the prompt with the highest overall score.

Underlying Research

Random search is a foundational technique in hyperparameter tuning, valued for its simplicity and effectiveness in outperforming grid search.
  • Baseline Strength: Research like “Random Sampling as a Strong Baseline for Prompt Optimisation” shows that even simple random sampling can be highly competitive.
  • Broad Applicability: It is often used as a starting point in prompt optimization toolkits and is highlighted in surveys for its ability to avoid local optima in discrete prompt spaces.

Next Steps