llm-json-schema-documentation
Document both INPUT and OUTPUT JSON schemas for LLM-driven features to prevent data flow confusion
What this skill does
# LLM JSON Schema Documentation
**Purpose:** Ensure LLM-driven features have complete schema documentation covering both input (what LLM receives) and output (what LLM returns).
## The Core Principle
**JSON Schema Over Text Instructions** - Tell the LLM what data structures exist, not how to write the content.
## Critical Requirements
### 1. Document BOTH Input and Output Schemas
**Common Mistake:** Documenting only OUTPUT schema while assuming LLM "just knows" what INPUT fields are available.
**✅ CORRECT Approach:**
```markdown
### Input Schema
When `npc_data` is present in your input, each NPC entry contains:
- `tier`: (string) Social HP tier - commoner | merchant | noble | god
- `name`: (string) NPC display name
- `role`: (string) NPC role/title
### Output Schema
When Social HP is active, populate:
- `social_hp_challenge.npc_tier`: (string) **Extract from npc_data.tier**
- `social_hp_challenge.npc_name`: (string) **Extract from npc_data.name**
```
**❌ WRONG Approach:**
```markdown
### Output Schema
- `social_hp_challenge.npc_tier`: (string) NPC tier
- `social_hp_challenge.npc_name`: (string) NPC name
# Missing: Where does the LLM get this data from?
```
### 2. Link Input to Output with Extraction Notes
**Pattern:**
- **Input field:** `npc_data.tier`
- **Output field:** `social_hp_challenge.npc_tier`
- **Extraction note:** "Extract from npc_data.tier"
This prevents "where does this data come from?" confusion.
### 3. Show Examples, Not Templates
**✅ Examples** (Reference - show good patterns):
```markdown
**Example Output:**
```
[SOCIAL SKILL CHALLENGE: Lady Ashwood]
Objective: Access family archives
Social HP: 5/5 | Status: RESISTING
```
```
**❌ Templates** (Prescription - constrains LLM):
```markdown
**Required Format:**
[SOCIAL SKILL CHALLENGE: {npc_name}]
Objective: {objective}
Social HP: {hp}/{max} | Status: {status}
# This tells LLM HOW to write, reducing autonomy
```
### 4. Server-Side Validation
**Pattern:** LLM Decides, Server Executes
```python
def validate_output(self):
"""Server validates LLM output structure."""
# Check required fields exist
if not self.social_hp_challenge.get("npc_name"):
logging_util.warning("Missing required field: npc_name")
# Cross-validate JSON with narrative
if self.social_hp_challenge and not self.narrative_contains_box():
logging_util.warning("JSON exists but narrative missing box")
```
## Implementation Checklist
When adding LLM-driven features:
- [ ] **Document INPUT schema** - What data does the LLM receive?
- [ ] List all available input fields
- [ ] Document field types and valid values
- [ ] Show example input data structure
- [ ] **Document OUTPUT schema** - What data must the LLM return?
- [ ] List all required output fields
- [ ] Document field types and constraints
- [ ] Show example output data structure
- [ ] **Link Input to Output** - How does data flow?
- [ ] Add extraction notes: "Extract from input_field.name"
- [ ] Show mapping between input and output fields
- [ ] Document any transformations or calculations
- [ ] **Provide Examples** - Show good patterns (not templates)
- [ ] Include narrative examples demonstrating natural integration
- [ ] Show JSON alongside narrative (both required)
- [ ] Avoid prescriptive templates that constrain LLM
- [ ] **Server Validation** - Enforce structure post-generation
- [ ] Validate required fields exist
- [ ] Type coercion for numeric/boolean fields
- [ ] Cross-validation between JSON and narrative
- [ ] Log warnings for missing/inconsistent data
## Example: Social HP System
**Problem:** LLM didn't know where to get `npc_tier` for output.
**Solution:**
1. **INPUT schema:** Documented `npc_data.tier` field exists
2. **OUTPUT schema:** Added `social_hp_challenge.npc_tier` field
3. **Link:** "Extract from npc_data.tier"
4. **Validation:** Server validates both JSON and narrative exist
**Files Updated:**
- `mvp_site/prompts/game_state_instruction.md`: INPUT/OUTPUT schemas
- `mvp_site/narrative_response_schema.py`: Server validation
- `CLAUDE.md`: Architectural principle documentation
## Why This Matters
**Prevents Confusion:**
- LLM knows what input fields are available to read
- LLM knows what output fields are expected
- Clear data flow from input → LLM → output
**Preserves Autonomy:**
- Schema defines WHAT data exists, not HOW to write content
- LLM decides narrative format based on context
- Examples show patterns, not rigid templates
**Enables Validation:**
- Server can validate structure post-generation
- Type coercion handles edge cases
- Cross-validation catches inconsistencies
## Anti-Patterns to Avoid
**❌ Template-Based Instructions**
```markdown
Write exactly this format:
[SOCIAL SKILL CHALLENGE: {npc_name}]
```
*Problem: Reduces LLM autonomy, constrains creativity*
**❌ Undocumented Input Fields**
```markdown
Return npc_tier in your output.
```
*Problem: LLM doesn't know where to get this data*
**❌ Missing Extraction Notes**
```markdown
- `output.tier`: (string) NPC tier
```
*Problem: No link to input field source*
**❌ Pure Text Instructions**
```markdown
When an NPC resists persuasion, describe their resistance narratively.
```
*Problem: No schema - server can't validate or track state*
## Related Documentation
- **CLAUDE.md**: "JSON Schema Over Text Instructions" principle
- **LLM Architecture Principles**: "LLM Decides, Server Executes"
- **Example Implementation**: Social HP PR #2915
---
**Last Updated:** 2025-01-07 (Social HP all-tiers PR)
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.