Zubnet AIAprenderWiki › Structured Output
Using AI

Structured Output

JSON Mode, Constrained Generation
Hacer que un modelo de IA responda en un formato específico y parseable por máquina — típicamente JSON, XML o un esquema definido. En vez de texto libre, el modelo produce data que tu código puede parsear de forma confiable. La mayoría de proveedores ahora soportan salida estructurada de forma nativa: defines un esquema, y el modelo garantiza que su respuesta se adhiera a él.

Por qué importa

En el momento en que pasas de chatbot a aplicación, necesitas salida estructurada. Tu código no puede parsear «¡Claro! Aquí están los resultados:» seguido de una lista. Necesitas {"results": [...]}. La salida estructurada es lo que hace la IA usable como componente en software en lugar de solo un generador de texto.

Deep Dive

There are three levels of structured output support. Prompt-based: you ask the model to "respond in JSON" and hope it complies (unreliable for complex schemas). Constrained decoding: the provider modifies the sampling process to only allow tokens that keep the output valid according to your schema (reliable, but can affect quality). Schema-validated: the provider guarantees conformance by retrying or repairing invalid outputs before returning them.

JSON Schema Is the Standard

Most providers (Anthropic, OpenAI, Google) converge on JSON Schema as the way to define structured outputs. You specify the expected fields, their types, which are required, and any enums or constraints. The model then generates JSON that matches. This works well for flat structures and moderately nested ones. Very deeply nested or recursive schemas can confuse models, and extremely large schemas eat into your context window.

When Not to Use It

Structured output isn't always the right choice. For creative writing, summarization, or explanations, free-form text is better. For data extraction, classification, or API integrations, structured output is essential. The middle ground — extracting structured data from unstructured input — is where it shines brightest. "Read this resume and extract: name, email, years of experience, top 3 skills" with a JSON schema is a solved problem.

Conceptos relacionados

← Todos los términos
← Streaming Suno →