Prompts That Generate Prompts
System prompt generators, persona generators, and task-specific prompt factories.
Prompt Factories
A prompt factory is a meta-prompt that generates multiple prompt variants for a given task. Instead of writing one prompt, you specify the task and constraints, and the factory produces a set of candidates you can test and select from.
Generating System Prompt Variants
Ask the model to generate N different system prompt variants for the same role, each with a different tone or communication style. This is the starting point for A/B testing system prompts.
import anthropic
client = anthropic.Anthropic(api_key='YOUR_API_KEY')
VARIANT_FACTORY_PROMPT = '''Generate {num_variants} different system prompt variants
for a coding assistant targeting junior developers.
Each variant should have a distinctly different approach:
- Variant 1: Friendly and encouraging mentor style
- Variant 2: Concise and technical style
- Variant 3: Socratic method (asks guiding questions instead of giving answers)
- Variant 4: Game-based, uses analogies and rewards
- Variant 5: Strict teacher who corrects mistakes firmly but fairly
For each variant output:
{{"id": 1, "style": "<style name>", "prompt": "<full system prompt>"}}
Return as a JSON array.'''
def generate_prompt_variants(num_variants=5):
import json
response = client.messages.create(
model='claude-opus-4-5', max_tokens=3000,
messages=[{'role': 'user', 'content':
VARIANT_FACTORY_PROMPT.format(num_variants=num_variants)}]
)
return json.loads(response.content[0].text)
variants = generate_prompt_variants(5)
for v in variants[:2]:
print(f'Variant {v["id"]} ({v["style"]}): {v["prompt"][:80]}...')All lessons in this course
- What Is Meta-Prompting?
- Prompts That Generate Prompts
- Self-Improving Prompt Systems
- Evaluation and Selection in Self-Improvement