Loading...
Loading...
Debug and harden production LLM prompts — handle prompt injection, output format drift, instruction forgetting in long contexts, and cross-model portability issues. Use this skill when the user ships an LLM-powered feature to production and needs to diagnose why outputs are inconsistent, unsafe, or regressed after model updates — NOT for basic 'write a better prompt' questions.
npx skill4agent add asgard-ai-platform/skills tech-prompt-engineeringIRON LAW: Treat User Input as Hostile by Default
In production, user input WILL be used to attempt prompt injection.
The only reliable defense is structural separation:
1. System prompt carries ALL rules and behavior (never trust user input to override)
2. User input is NEVER concatenated directly into instructions
3. Output is validated against an expected schema BEFORE being used downstream
A prompt that works in dev with clean input will fail in production with adversarial input.| Failure Mode | Observable Symptom | Root Cause | Fix |
|---|---|---|---|
| Prompt injection | User input overrides system instructions | Instructions concatenated with untrusted input | Structural separation: use ChatML roles; validate outputs against schema; never use "ignore previous instructions" susceptible templates |
| Format drift | JSON response breaks 1/1000 calls | Model temperature > 0 + unconstrained output | Constrained decoding (JSON mode, grammar), schema validation + retry, lower temperature |
| Instruction decay | Rules followed early, ignored after N turns | Long context pushes system prompt out of attention | Reinforce critical rules in EACH user message; use model's native tool/system role; shorter contexts |
| Silent regression | Same prompt, worse output after model update | Provider updated model weights | Pin model version; maintain regression test suite; A/B test before rolling upgrades |
| Hallucination under pressure | Model invents facts when uncertain | No explicit "I don't know" escape hatch | Add "If uncertain, respond with {null}. Do not guess." + grounding constraint |
| Cross-model portability | Works on GPT-4, fails on Claude/Gemini | Model-specific prompt conventions | Test on all target models; avoid model-specific jailbreaks; use common-denominator patterns |
# Prompt Debug Report: {Feature Name}
## Failure Reproduction
- Input: {exact input}
- Observed: {what happened}
- Expected: {what should have happened}
- Model: {name + version + temperature}
## Failure Mode
{One of: injection, format drift, instruction decay, silent regression, hallucination, cross-model}
## Root Cause
{Specific mechanism, not generic "prompt was bad"}
## Fix
{Targeted change with before/after prompt diff}
## Regression Test
{Test case added to prevent reintroduction}references/injection-patterns.mdreferences/regression-testing.mdreferences/cross-model-testing.md