llm-debugger
Diagnoses LLM output failures including hallucinations, constraint violations, format errors, and reasoning issues. Provides root cause classification, prompt fixes, tool improvements, and new test cases. Use for "debugging AI", "fixing prompts", "quality issues", or "output errors".
What this skill does
# LLM Debugger
Systematically diagnose and fix LLM output issues.
## Failure Taxonomy
```python
class FailureType(Enum):
HALLUCINATION = "hallucination"
FORMAT_VIOLATION = "format_violation"
CONSTRAINT_BREAK = "constraint_break"
REASONING_ERROR = "reasoning_error"
TOOL_MISUSE = "tool_misuse"
REFUSAL = "unexpected_refusal"
INCOMPLETE = "incomplete_output"
```
## Root Cause Analysis
```python
def diagnose_failure(input: str, output: str, expected: dict) -> dict:
"""Identify why LLM output failed"""
issues = []
# Check format
if expected.get("format") == "json":
try:
json.loads(output)
except:
issues.append({
"type": FailureType.FORMAT_VIOLATION,
"details": "Invalid JSON output"
})
# Check required fields
if expected.get("required_fields"):
for field in expected["required_fields"]:
if field not in output:
issues.append({
"type": FailureType.INCOMPLETE,
"details": f"Missing required field: {field}"
})
# Check constraints
if expected.get("max_length"):
if len(output) > expected["max_length"]:
issues.append({
"type": FailureType.CONSTRAINT_BREAK,
"details": f"Output too long: {len(output)} > {expected['max_length']}"
})
# Check for hallucination indicators
if contains_hallucination_markers(output):
issues.append({
"type": FailureType.HALLUCINATION,
"details": "Contains fabricated information"
})
return {
"has_issues": len(issues) > 0,
"issues": issues,
"primary_issue": issues[0] if issues else None
}
def contains_hallucination_markers(output: str) -> bool:
"""Detect common hallucination patterns"""
markers = [
r'According to.*that doesn\'t exist',
r'In \d{4}.*before that year',
r'contradicts itself',
]
return any(re.search(marker, output, re.IGNORECASE) for marker in markers)
```
## Prompt Fixes
````python
PROMPT_FIXES = {
FailureType.FORMAT_VIOLATION: """
Add strict format instructions:
"Output MUST be valid JSON with this exact structure:
```json
{{"field1": "value", "field2": 123}}
````
Do not add any text before or after the JSON."
""",
FailureType.HALLUCINATION: """
Add grounding instructions:
"Base your response ONLY on the provided context.
If information is not in the context, say 'I don't have that information.'
Never make up facts or details."
""",
FailureType.CONSTRAINT_BREAK: """
Add explicit constraints:
"Your response must be:
- Maximum 200 words
- No code examples
- Professional tone only"
""",
FailureType.REASONING_ERROR: """
Add step-by-step reasoning:
"Think through this step by step:
1. First, identify...
2. Then, consider...
3. Finally, conclude..."
""",
}
def suggest_prompt_fix(diagnosis: dict, current_prompt: str) -> str:
"""Generate improved prompt based on diagnosis"""
primary_issue = diagnosis["primary_issue"]
if not primary_issue:
return current_prompt
fix = PROMPT_FIXES[primary_issue["type"]]
return f"""{current_prompt}
IMPORTANT INSTRUCTIONS:
{fix}
"""
````
## Tool Improvements
```python
def suggest_tool_fixes(diagnosis: dict, tool_schema: dict) -> dict:
"""Improve tool schema to prevent misuse"""
fixes = {}
for issue in diagnosis["issues"]:
if issue["type"] == FailureType.TOOL_MISUSE:
# Make required parameters more explicit
fixes["parameters"] = {
**tool_schema["parameters"],
"description": "REQUIRED: " + tool_schema["parameters"].get("description", "")
}
# Add examples
fixes["examples"] = [
{
"params": {"query": "example search"},
"description": "Use for finding information"
}
]
return {**tool_schema, **fixes}
````
## Test Case Generation
```python
def generate_test_cases(diagnosis: dict, failed_input: str, failed_output: str) -> List[dict]:
"""Create regression test cases from failures"""
test_cases = []
# Test case for the specific failure
test_cases.append({
"input": failed_input,
"expected_behavior": "Should not " + diagnosis["primary_issue"]["details"],
"validation": lambda output: not has_same_issue(output, diagnosis),
})
# Edge cases based on failure type
if diagnosis["primary_issue"]["type"] == FailureType.FORMAT_VIOLATION:
test_cases.append({
"input": failed_input,
"validation": lambda output: is_valid_json(output),
"description": "Output must be valid JSON"
})
# Similar inputs that might trigger same issue
similar_inputs = generate_similar_inputs(failed_input)
for inp in similar_inputs:
test_cases.append({
"input": inp,
"validation": lambda output: not has_same_issue(output, diagnosis),
})
return test_cases
```
## Debugging Workflow
```python
def debug_llm_output(
prompt: str,
output: str,
expected: dict,
context: dict = {}
) -> dict:
"""Complete debugging workflow"""
# 1. Diagnose issue
diagnosis = diagnose_failure(prompt, output, expected)
if not diagnosis["has_issues"]:
return {"status": "ok", "diagnosis": diagnosis}
# 2. Generate fixes
fixed_prompt = suggest_prompt_fix(diagnosis, prompt)
# 3. Create test cases
test_cases = generate_test_cases(diagnosis, prompt, output)
# 4. Test fix
test_output = llm(fixed_prompt)
fix_works = diagnose_failure(fixed_prompt, test_output, expected)["has_issues"] == False
return {
"status": "issues_found",
"diagnosis": diagnosis,
"fixes": {
"prompt": fixed_prompt,
"fix_verified": fix_works,
},
"test_cases": test_cases,
"recommendations": generate_recommendations(diagnosis, context)
}
```
## Interactive Debugging
```python
def interactive_debug():
"""Interactive debugging session"""
print("LLM Debugger - Interactive Mode")
prompt = input("Enter prompt: ")
expected_output = input("Expected output format (json/text): ")
output = llm(prompt)
print(f"\nGenerated output:\n{output}\n")
if input("Does this look correct? (y/n): ").lower() == 'n':
diagnosis = diagnose_failure(prompt, output, {"format": expected_output})
print("\nDiagnosis:")
for issue in diagnosis["issues"]:
print(f"- {issue['type'].value}: {issue['details']}")
print("\nSuggested fix:")
print(suggest_prompt_fix(diagnosis, prompt))
```
## Best Practices
1. **Reproduce consistently**: Multiple runs
2. **Isolate variables**: Test prompt changes one at a time
3. **Check examples**: Are few-shot examples clear?
4. **Validate constraints**: Are they explicit enough?
5. **Test edge cases**: Boundary conditions
6. **Log everything**: Inputs, outputs, issues
7. **Iterate systematically**: Track what fixes work
## Output Checklist
- [ ] Failure taxonomy defined
- [ ] Root cause analyzer
- [ ] Prompt fix suggestions
- [ ] Tool schema improvements
- [ ] Test case generator
- [ ] Fix verification
- [ ] Debugging workflow
- [ ] Recommendations engine
- [ ] Interactive debugger
- [ ] Logging system
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.