implement-structured-outputs

Implements constrained decoding and schema validation for LLM responses in backend services.

Updated Feb 10, 2026
One-click install
npx skills add https://github.com/vesviet/agent-skills --skill implement-structured-outputs-vesviet
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: implement-structured-outputs
Source: https://github.com/vesviet/agent-skills/tree/main/core/skills/backend/implement-structured-outputs
Command: npx skills add https://github.com/vesviet/agent-skills --skill implement-structured-outputs-vesviet

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? LLM responses are free-form text that breaks downstream code when parsed with regex or ad-hoc string handling. This Skill enforces strict JSON Schema guarantees on model generations so structured data reaches business logic without parsing failures. ## Core Features & Use Cases - Constrained Decoding: Configures provider-native structured output modes (OpenAI response_format with strict: true, Gemini responseSchema, or grammar constraints for vLLM/Ollama) to guarantee JSON syntax at the token level. - Dual-Layer Validation: Defines canonical schemas in Zod or Pydantic v2, then validates decoded payloads at runtime to enforce enum bounds and cross-field business invariants. - Bounded Repair Loops: Injects validation error diffs into one-turn repair prompts with a hard ceiling of 2 retries before returning a structured domain error. - Use Case: A backend service extracts order details from customer emails via an LLM. Use this Skill to guarantee every response matches the order schema, automatically repair rare failures, and never let malformed JSON reach the database layer. ## Quick Start Use the implement-structured-outputs skill to add strict JSON Schema validation and constrained decoding to my LLM integration in the orders service.

Frequently Asked Questions about implement-structured-outputs

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I get structured JSON output from an LLM API?▼

Use provider-native constrained decoding instead of parsing raw text. For OpenAI set response_format with type json_schema and strict true; for Gemini set responseMimeType to application/json with a responseSchema; for self-hosted models pass grammar constraints via XGrammar or Outlines.

Zod vs Pydantic for LLM output validation?▼

Zod fits TypeScript backends with schema.safeParse for runtime checks, while Pydantic v2 suits Python services using TypeAdapter.validate_json. Both export to JSON Schema 2020-12 for provider compatibility, so choose based on your service language.

Why should I avoid regex parsing of LLM responses?▼

Regex parsing is brittle because LLM output formatting varies with whitespace, code fences, and truncation. Constrained decoding guarantees JSON syntax at the token generation layer, and schema validation enforces types, making regex extraction unnecessary and prohibited in production pipelines.

What happens when LLM output fails schema validation?▼

Inject the exact validation error diff into a one-turn repair prompt and retry with bounded backoff. Cap retries at a maximum of 2 attempts, then return a structured domain error rather than looping indefinitely or passing invalid data downstream.

Does constrained decoding reduce model reasoning quality?▼

Grammar constraints can compress reasoning space, so include a thought_process or reasoning field in the schema before final output fields. This preserves the model's reasoning capacity, and you strip the field before returning results to callers.