Iterate on LLM prompts with structured evaluation and self-correction. Test prompts against ground truth, compare models, track version history. Self-correction loop sends invalid outputs back to LLM for fixing. Supports both taxonomy classification and QRA (Question-Reasoning-Answer) generation.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Iterate on LLM prompts with structured evaluation and self-correction. Test prompts against ground truth, compare models, track version history. Self-correction loop sends invalid outputs back to LLM for fixing. Supports both taxonomy classification and QRA (Question-Reasoning-Answer) generation.
Sends correction back to LLM - "You used invalid tags X. Valid options are Y. Please fix."
Tracks correction rounds - Metrics show how often LLM needed help
This gives the model a chance to self-correct rather than silently failing.
Quick Start
cd /home/graham/workspace/experiments/pi-mono/.pi/skills/prompt-lab
# Find the smallest model that works (NEW!)
./run.sh find-minimum --ground-truth queryspec.json --threshold 0.80
# Run evaluation with self-correction enabled (default)
./run.sh eval --prompt taxonomy_v1 --model deepseek
# Compare multiple models on same prompt
./run.sh compare --prompt taxonomy_v1 --models "deepseek,gpt-4o"# View evaluation history
./run.sh history --prompt taxonomy_v1
find-minimum - Find Smallest Accurate Model (NEW!)
Automatically test models from smallest to largest, stopping at the first model that meets your accuracy threshold. Supports both Chutes API and local Ollama.
# Find smallest model for QuerySpec with 80% accuracy threshold
./run.sh find-minimum --ground-truth queryspec.json --threshold 0.80
# Prefer local Ollama models (default)
./run.sh find-minimum -g queryspec.json -t 0.80 --prefer-local
# Test Chutes API models instead
./run.sh find-minimum -g queryspec.json -t 0.80 --no-prefer-local
# Options:# --ground-truth, -g Ground truth JSON file (required)# --threshold, -t Minimum accuracy threshold (default: 0.80)# --prompt, -p Optional prompt file# --prefer-local Prefer local Ollama (default: true)# --max-models Max models to test (default: 10)# --verbose, -v Show per-case details
Chutes (API): Qwen2.5-Coder-32B, Qwen3-32B, DeepSeek-V3, etc.
Output:
Sorted table of all tested models with JSON% and Action%
Recommended model with size and provider
Results saved to results/find_minimum_*.json
eval - Run Evaluation
./run.sh eval --prompt taxonomy_v1 --model deepseek
# Options:# --prompt NAME Prompt version to test# --model NAME Model to use (deepseek, gpt-4o, etc.)# --cases N Number of test cases (default: all)# --max-corrections N Max self-correction rounds (default: 2)# --no-correction Disable self-correction loop# --task-name NAME Task-monitor task name for quality gate# --verbose Show per-case details
0=Relationships (Technique->Control), 1=Simple Control QRA
--threshold <float>
0.85
Citation grounding threshold
--min-anchoring
0.995
Entity anchoring threshold (99.5% for LLM non-determinism)
--min-ambiguity
0.995
Ambiguity gate threshold (99.5% for LLM non-determinism)
--min-grounding
0.90
Citation grounding threshold
--json
false
Output structured JSON summary
--json-stream
false
Output NDJSON per case (streaming progress)
--task-monitor/--no-task-monitor
true
Enable/disable task-monitor integration
--converge
false
Enable iterative convergence mode
Task-Monitor Integration
prompt-lab integrates with the centralized task-monitor for live progress tracking:
# Run test with task-monitor (enabled by default)
./run.sh test-sparta --cases 100
# View progress in task-monitor TUIcd ~/.pi/skills/task-monitor
uv run python monitor.py tui --filter prompt-lab
# Or check state file directlycat /path/to/prompt-lab/prompt_lab_task_state.json | jq
Real-time progress monitoring via tail -f results.jsonl | jq
Integration with streaming parsers
Resume from partial runs
Validation Features
Ambiguity Gate: Checks for sufficient length and context keyword usage.
Entity Anchoring: Verifies questions explicitly name the subject entities.
Citation Grounding: Verifies answers are derived verbatim from source text.
history - View History
./run.sh history --prompt taxonomy_v1
# Shows all evaluation runs with scores over time
analyze - Analyze Past Results
./run.sh analyze --prompt taxonomy_v1
# Analyzes error patterns across all previous evaluations:# - Most common invalid tags# - Cases needing correction# - Performance trend over time# - Suggests improvements based on patterns
optimize - LLM-Powered Prompt Optimization
./run.sh optimize --prompt taxonomy_v1
# Uses LLM to analyze error cases and suggest prompt improvements:# - Reviews cases with low F1 scores# - Identifies ambiguous tag definitions# - Generates revised prompt sections# - Saves suggestions for review
Self-Correction Prompt
When invalid tags are detected, this correction message is sent back to the LLM:
Your response contained invalid tags that are not in the allowed vocabulary.
Invalid tags you used: {rejected_tags}
Valid conceptual tags (Tier 0): Corruption, Fragility, Loyalty, Precision, Resilience, Stealth
Valid tactical tags (Tier 1): Detect, Evade, Exploit, Harden, Isolate, Model, Persist, Restore
Please correct your response. Return ONLY valid JSON with tags from the allowed vocabulary above.
Do NOT invent new categories. Only use the exact tag names listed.
Quality Gates
Evaluation enforces quality gates:
F1 >= 0.8 - Must achieve 80% F1 score against ground truth
Correction Success >= 90% - Self-correction must succeed 90% of the time
If quality gates fail, exit code is 1 (for CI/CD integration).
Increased diversity from 1-2 to 4-7 QRAs per input
"Each extracts DIFFERENT information"
Reduced duplicate answers
"EXACT verbatim excerpt" for citations
Stopped control ID citations, enforced text snippets
What Didn't Work:
Anti-Pattern
Problem
Template examples in prompts
Caused repetitive outputs
Generic "be grounded" instructions
Too vague, still hallucinated
"Generate ONE per type"
Limited coverage of source material
No deduplication guidance
Repeated same answer in different words
"Citation: [CONTROL_ID]"
Generated IDs instead of text excerpts
Refined QRA Prompt Template
The following prompt pattern generates properly grounded QRAs:
You are a space-based cybersecurity expert generating Question-Reasoning-Answer pairs
for SPARTA. Think like a LEGAL LLM: every claim MUST cite precedent from the provided text.
STRICT GROUNDING RULE: If information is NOT in the provided text, you CANNOT include
it in your answer. Do NOT add external knowledge, mitigation advice, or implications
not directly stated.
Return JSON: {"items": [{"question": "...",
"question_type": "simple|medium|complex|reversal_curse",
"questioner_persona": "lay_person|project_manager|cybersecurity_expert",
"reasoning": "...", "answer": "...",
"citations": ["EXACT verbatim excerpt from text"],
"confidence": "strong|partial",
"conceptual_tags": [], "tactical_tags": []}]}
GENERATE ALL REASONABLE NON-DUPLICATE QUESTIONS:
- Simple, Medium, Complex levels + Reversal curse where applicable
- Each extracts DIFFERENT information from the text
- NEVER add information not in the source text
TAXONOMY: C=[Corruption,Fragility,Loyalty,Precision,Resilience,Stealth],
T=[Detect,Evade,Exploit,Harden,Isolate,Model,Persist,Restore]