ai-output-validation
Validates, parses, and sanitizes AI-generated outputs before they reach end users or downstream systems. Structured output enforcement, schema validation, and fallback handling.
pinned to #f47f948updated 2 weeks ago
Ask your AI client: “install skills/ai-output-validation”.
Requires the metahub MCP server installed in your client. Set up MCP.
mh install skills/ai-output-validationmetahub onboarded this repo on the author's behalf.
If you own github.com/DevelopersGlobal/ai-agent-skills on GitHub, claim the listing to take over publishing. Your claim preserves the existing eval history and badges; only the curator label is replaced with verified-publisher on your next publish.
Stars
64
Last commit
2 weeks ago
Latest release
published
- #ai
- #ai-agents
- #antigravity
- #artificial-intelligence
- #claude
- #claude-code-plugin
- #claude-skills
- #codex
- #cursor
- #skills
Evaluation report
WarningsAutomated checks the publisher passed at publish time — structure, docs, safety, and whether the artifact behaves as claimed.f47f948· 2 weeks ago
Kind-specific
31Skill: SKILL.md present
found at skills/ai-output-validation/SKILL.md · frontmatter source: SKILL.md
Skill: body content present
663 words · 4,455 chars · 12 sections
Skill: triggers declaredwarn
No `trigger` phrases in SKILL.md frontmatter
Add `trigger:` lines so Claude knows when to activate this skill — e.g. `when building MCP servers` or `for diagram creation`.
Skill: allowed-tools scope
no allowed-tools restriction (Claude may use anything)
Release history
1- releasecurrentf47f948warn2 weeks ago
Contents
Overview
AI models produce unstructured text by default. In production pipelines, unstructured outputs cause brittle parsing, unexpected behavior, and silent failures. This skill enforces structured output generation and validation at every AI system boundary.
When to Use
- Any AI pipeline where output is used programmatically (not just displayed to a user)
- When AI output feeds into another system, database, or agent
- When building agentic systems that make decisions based on AI output
- When AI generates code, SQL, JSON, or other structured formats
Process
Step 1: Define Output Schema Before Prompting
- Define the exact structure you need BEFORE writing the prompt.
- Use JSON Schema or Pydantic/Zod models to formalize the expected output.
- Example schema:
{ "type": "object", "required": ["summary", "action", "confidence"], "properties": { "summary": {"type": "string", "maxLength": 200}, "action": {"type": "string", "enum": ["approve", "reject", "review"]}, "confidence": {"type": "number", "minimum": 0, "maximum": 1} } } - Design the schema to be minimal — only what you actually need.
Verify: Schema is defined and versioned before any prompt is written.
Step 2: Prompt for Structured Output
- Explicitly instruct the model to output in your defined format.
- Include the schema or an example in the prompt.
- Use models/APIs that support structured output natively where available (OpenAI structured outputs, Gemini JSON mode, Anthropic tool use).
- Prompt pattern:
Respond ONLY with valid JSON matching this schema: {schema} Do not include explanation or markdown. Output raw JSON only.
Verify: Prompt explicitly requests structured output with schema reference.
Step 3: Validate and Parse Output
- Parse the output against your schema — never use raw AI output directly.
- If parsing fails:
- Log the raw output and the parse error
- Retry with a clarification prompt (max 2 retries)
- After 2 failures: return a structured error, not a crash
- Validate semantic constraints beyond the schema:
- Is the
confidencescore consistent with theaction? - Are referenced IDs in the database?
- Are dates in the valid range?
- Is the
Verify: All AI outputs pass schema validation before use. Failed validations are logged.
Step 4: Sanitize for Downstream Use
- If AI output will be rendered as HTML: sanitize against XSS.
- If AI output will be executed as code: sandbox it and review before execution.
- If AI output will be stored in a database: sanitize against injection.
- Never trust AI output the way you'd trust your own code — it's user-generated content.
Verify: AI output is sanitized appropriate to its destination.
Step 5: Monitor Output Quality
- Log the schema validation pass/fail rate.
- Sample and review AI outputs regularly for semantic correctness.
- Alert on high validation failure rates (>5%).
Verify: Validation metrics are tracked. Alert configured.
Common Rationalizations (and Rebuttals)
| Excuse | Rebuttal |
|---|---|
| "The model outputs valid JSON 99% of the time" | That 1% causes production incidents. Always validate. |
| "We display it to users, not parse it" | Users act on AI output. Wrong output drives wrong actions. |
| "Structured output adds latency" | Validation is microseconds. Debugging unvalidated output is hours. |
| "The model is deterministic enough" | No LLM is deterministic enough to skip validation. |
Red Flags
- AI output used directly without schema validation
JSON.parse()without try/catch around AI output- AI-generated SQL or code executed without review
- No logging of validation failures
- AI output rendered as HTML without sanitization
Verification
- Output schema defined and versioned
- Prompt explicitly requests structured output
- Schema validation on every AI response
- Retry logic for validation failures (max 2 retries)
- Semantic validation beyond schema (constraint checks)
- Sanitization applied appropriate to output destination
- Validation failure rate monitored
References
Reviews
No reviews yet. Be the first.
Related
Planning With Files
Claude Code skill implementing Manus-style persistent markdown planning — the workflow pattern behind the $2B acquisition.
Guizang Ppt Skill
AI-agent Skill for generating polished HTML slide decks: editorial magazine and Swiss layouts, image prompts, social covers, and a WebGL/low-power presentation runtime.
orchestration-patterns
>
mh install skills/ai-output-validation