WhoBuilt

No more bad outputs with structured generation

Oct 14, 2024· 16 min· 11K views·Watch on YouTube

Speaker

Remi Louf, co-author and co-maintainer of Outlines and CEO and co-founder of Dottxt, explains structured generation and its role in making language model outputs more reliable for software workflows.

Why output structure matters

Louf describes a common failure: a model asked to extract flight details from emails may return invalid JSON even after extensive prompting or function calling. Because software depends on reliable interfaces, inconsistent model outputs make it harder to build dependable agent systems.

How Outlines guides generation

Outlines is a Python library for adding structured generation to existing workflows, with integrations for open models and serving systems such as vLLM and TGI. It can constrain output with regular expressions, JSON Schema, Pydantic models, and custom types such as three-letter airport codes. Louf explains that Outlines masks tokens that would violate the requested structure.

Reliability, speed, and accuracy results

Louf argues that structured text appears in many tasks, from JSON to GSM8K math problems. In a Predibase experiment, Mistral 7B produced valid JSON 17.7% of the time without structured generation and 99.9% with it. He also reports that structured generation can reduce generated tokens, match eight-shot GSM8K accuracy with one shot, and raise Phi-3 Medium function-calling accuracy from 86% to 96.5%, above the cited GPT-4 benchmark score of 93.5%.

Broader constraints and next steps

Louf says Outlines has expanded from regular expressions to context-free grammars for tasks such as code and protein structures. The team is also working on semantic constraints for text-to-SQL, aiming to ensure generated queries run even when correctness of the result cannot be guaranteed. Future work aims to avoid unnecessary computation inside the model.

Takeaways

  • Use structured generation to enforce output formats instead of relying on prompts and post-generation parsing.
  • Treat output schemas as part of the interface when connecting language models to software.
  • Constrain only the structure your task requires, including field types such as airport codes.
  • Measure token counts as well as latency: shorter constrained outputs can reduce generation work.
  • Test structured generation on small open models; it may improve task accuracy and reduce the need for examples.

Mentioned in this talk

Search inside this talk

What was claimed 15

Show all 15 facts

Related talks