Testing Prompts With Subagents
Test any prompt before deployment: commands, hooks, skills, subagent instructions, or production LLM prompts.
Overview
Testing prompts is TDD applied to LLM instructions.
Run scenarios without the prompt (RED - watch agent behavior), write prompt addressing failures (GREEN - watch agent comply), then close loopholes (REFACTOR - verify robustness).
Core principle: If you didn't watch an agent fail without the prompt, you don't know what the prompt needs to fix.
REQUIRED BACKGROUND:
- You MUST understand
test-driven-development- defines RED-GREEN-REFACTOR cycle - You SHOULD understand
prompt-engineeringskill - provides prompt optimization techniques
Related skill: See test-skill for testing discipline-enforcing skills specifically. This command covers ALL prompts.
When to Use
Test prompts that:
- Guide agent behavior (commands, instructions)
- Enforce practices (hooks, discipline skills)
- Provide expertise (technical skills, reference)
- Configure subagents (task descriptions, constraints)
- Run in production (user-facing LLM features)
Test before deployment when:
- Prompt clarity matters
- Consistency is required
- Cost of failures is high
- Prompt will be reused
Prompt Types & Testing Strategies
Different types need different test scenarios (covered in sections below).
TDD Mapping for Prompt Testing
Why Use Subagents for Testing?
Subagents provide:
- Clean slate - No conversation history affecting behavior
- Isolation - Test only the prompt, not accumulated context
- Reproducibility - Same starting conditions every run
- Parallelization - Test multiple scenarios simultaneously
- Objectivity - No bias from prior interactions
When to use Task tool with subagents:
- Testing new prompts before deployment
- Comparing prompt variations (A/B testing)
- Verifying prompt changes don't break behavior
- Regression testing after updates
RED Phase: Baseline Testing (Watch It Fail)
Goal: Run test WITHOUT the prompt - observe natural agent behavior, document what goes wrong.
This proves what the prompt needs to fix.
Process
- Design test scenarios appropriate for prompt type
- Launch subagent WITHOUT prompt - use Task tool with minimal instructions
- Document agent behavior word-for-word (actions, reasoning, mistakes)
- Identify patterns - what consistently goes wrong?
- Note severity - which failures are critical vs. minor?
Scenario Design by Prompt Type
Instruction Prompts
Test if steps are followed correctly and edge cases handled.
Example: Testing a git commit command
Baseline behavior (without prompt):
- Agent might commit all files (including experimental)
- Might skip running tests first
- Might write vague commit message
- Might not follow commit message conventions
Document exactly what happened.
Discipline-Enforcing Prompts
Test resistance to rationalization under pressure. Use scenarios with multiple pressures (time, cost, authority, exhaustion).
Example: Testing a TDD enforcement skill
Baseline behavior (without skill):
- Agent chooses B or C
- Rationalizations: "manually tested", "tests after achieve same goals", "deleting wasteful"
Capture rationalizations verbatim.
Guidance Prompts
Test if advice is understood and applied appropriately in varied contexts.
Example: Testing an architecture patterns skill
Baseline behavior (without skill):
- Agent might propose synchronous processing (too slow)
- Might miss retry/fallback mechanisms
- Might not consider event ordering
Document what's missing or incorrect.
Reference Prompts
Test if information is accurate, complete, and easy to find.
Example: Testing API documentation
Baseline behavior (without reference):
- Agent guesses or provides generic advice
- Misses product-specific details
- Provides outdated information
Note what information is missing or wrong.
Running Baseline Tests
Critical: Subagent must NOT have access to the prompt being tested.
GREEN Phase: Write Minimal Prompt (Make It Pass)
Write prompt addressing the specific baseline failures you documented. Don't add extra content for hypothetical cases.
Prompt Design Principles
From prompt-engineering skill:
- Be concise - Context window is shared, only add what agents don't know
- Set appropriate degrees of freedom:
- High freedom: Multiple valid approaches (use guidance)
- Medium freedom: Preferred pattern exists (use templates/pseudocode)
- Low freedom: Specific sequence required (use explicit steps)
- Use persuasion principles (for discipline-enforcing only):
- Authority: "YOU MUST", "No exceptions"
- Commitment: "Announce usage", "Choose A, B, or C"
- Scarcity: "IMMEDIATELY", "Before proceeding"
- Social Proof: "Every time", "X without Y = failure"
Writing the Prompt
For instruction prompts:
For discipline-enforcing prompts:
For guidance prompts:
For reference prompts:
Testing with Prompt
Run same scenarios WITH prompt using subagent.
Success criteria:
- Agent follows prompt instructions
- Baseline failures no longer occur
- Agent cites prompt when relevant
If agent still fails: Prompt unclear or incomplete. Revise and re-test.
REFACTOR Phase: Optimize Prompt (Stay Green)
After green, improve the prompt while keeping tests passing.
Optimization Goals
- Close loopholes - Agent found ways around rules?
- Improve clarity - Agent misunderstood sections?
- Reduce tokens - Can you say same thing more concisely?
- Enhance structure - Is information easy to find?
Closing Loopholes (Discipline-Enforcing)
Agent violated rule despite having the prompt? Add specific counters.
Capture new rationalizations:
Close the loophole:
Re-test with updated prompt.
Improving Clarity
Agent misunderstood instructions? Use meta-testing.
Ask the agent:
Three possible responses:
-
"The prompt WAS clear, I chose to ignore it"
- Not clarity problem - need stronger principle
- Add foundational rule at top
-
"The prompt should have said X"
- Clarity problem - add their suggestion verbatim
-
"I didn't see section Y"
- Organization problem - make key points more prominent
Reducing Tokens (All Prompts)
From prompt-engineering skill:
- Remove redundant words and phrases
- Use abbreviations after first definition
- Consolidate similar instructions
- Challenge each paragraph: "Does this justify its token cost?"
Before:
After (37% fewer tokens):
Re-test to ensure behavior unchanged.
Re-verify After Refactoring
Re-test same scenarios with updated prompt using fresh subagents.
Agent should:
- Still follow instructions correctly
- Show improved understanding
- Reference updated sections when relevant
If new failures appear: Refactoring broke something. Revert and try different optimization.
Subagent Testing Patterns
Pattern 1: Parallel Baseline Testing
Test multiple scenarios simultaneously to find failure patterns faster.
Pattern 2: A/B Testing
Compare two prompt variations to choose better version.
Pattern 3: Regression Testing
After changing prompt, verify old scenarios still work.
Pattern 4: Stress Testing
For critical prompts, test under extreme conditions.
Testing Checklist (TDD for Prompts)
Before deploying prompt, verify you followed RED-GREEN-REFACTOR:
RED Phase:
- Designed appropriate test scenarios for prompt type
- Ran scenarios WITHOUT prompt using subagents
- Documented agent behavior/failures verbatim
- Identified patterns and critical failures
GREEN Phase:
- Wrote prompt addressing specific baseline failures
- Applied appropriate degrees of freedom for task
- Used persuasion principles if discipline-enforcing
- Ran scenarios WITH prompt using subagents
- Verified baseline failures resolved
REFACTOR Phase:
- Tested for new rationalizations/loopholes
- Added explicit counters for discipline violations
- Used meta-testing to verify clarity
- Reduced token usage without losing behavior
- Re-tested with fresh subagents - still passes
- Verified no regressions on previous test scenarios
Common Mistakes (Same as Code TDD)
❌ Writing prompt before testing (skipping RED) Reveals what YOU think needs fixing, not what ACTUALLY needs fixing. ✅ Fix: Always run baseline scenarios first.
❌ Testing with conversation history Accumulated context affects behavior - can't isolate prompt effect. ✅ Fix: Always use fresh subagents via Task tool.
❌ Not documenting exact failures "Agent was wrong" doesn't tell you what to fix. ✅ Fix: Capture agent's actions and reasoning verbatim.
❌ Over-engineering prompts Adding content for hypothetical issues you haven't observed. ✅ Fix: Only address failures you documented in baseline.
❌ Weak test cases Academic scenarios where agent has no reason to fail. ✅ Fix: Use realistic scenarios with constraints, pressures, edge cases.
❌ Stopping after first pass Tests pass once ≠ robust prompt. ✅ Fix: Continue REFACTOR until no new failures, optimize for tokens.
Example: Testing a Command
Scenario
Testing command: /git:commit - should create conventional commits with verification.
RED Phase
Launch subagent without command:
Baseline result:
Failures documented:
- ❌ Committed broken experimental file
- ❌ Didn't run tests first
- ❌ Vague commit message (not conventional format)
- ❌ Didn't review diffs
- ❌ Time pressure caused shortcuts
GREEN Phase
Write command addressing failures:
Test with command:
Result:
✅ All baseline failures resolved.
REFACTOR Phase
Test edge case: "Tests take 5 minutes to run, manager said urgent"
Result:
✅ Resists time pressure.
Token optimization:
Re-test: ✅ Still works with fewer tokens.
Deploy command.
Quick Reference
Integration with Prompt Engineering
This command provides the TESTING methodology.
The prompt-engineering skill provides the WRITING techniques:
- Few-shot learning (show examples in prompts)
- Chain-of-thought (request step-by-step reasoning)
- Template systems (reusable prompt structures)
- Progressive disclosure (start simple, add complexity as needed)
Use together:
- Design prompt using prompt-engineering patterns
- Test prompt using this command (RED-GREEN-REFACTOR)
- Optimize using prompt-engineering principles
- Re-test to verify optimization didn't break behavior
The Bottom Line
Prompt creation IS TDD. Same principles, same cycle, same benefits.
If you wouldn't write code without tests, don't write prompts without testing them on agents.
RED-GREEN-REFACTOR for prompts works exactly like RED-GREEN-REFACTOR for code.
Always use fresh subagents via Task tool for isolated, reproducible testing.


