Structured generation library by .txt (dottxt-ai). Guarantees schema-valid outputs at generation time via FSM-based logits masking — no post-processing or retries. Supports regex, JSON schema (Pydantic or raw), CFG, and multiple-choice constraints. Backends: Transformers, vLLM, llama.cpp, MLX, Ollama, OpenAI, Mistral, Gemini. Core FSM engine split into separate outlines-core package (Rust). Two coexisting APIs: legacy outlines.models + outlines.generate.* style, and new 1.x outlines.from_* + model(prompt, Schema) style.
pip install outlinesVerified import paths — ran on the pinned version, not inferred.
1.x API: pass output type directly to model call. For local models, swap outlines.from_openai for outlines.from_transformers.
Upgrade to Python 3.10+.
Use outlines.processors directly (RegexLogitsProcessor, JSONLogitsProcessor, CFGLogitsProcessor) for custom logits processor integration.
Use high-level outlines.generate.json() or outlines.generate.regex() instead of constructing FSMs directly.
Install the required extra: pip install 'outlines[transformers]', 'outlines[vllm]', 'outlines[llamacpp]', etc.
Pick one API style per codebase. New style is recommended. Old style is still valid for outlines.generate.* generators.
Use local backends (Transformers, vLLM, llama.cpp) for hard regex/CFG constraints. API backends only support JSON schema via the provider's native structured output API.
Create generator/model+schema pair once at startup and call it repeatedly. Do not re-instantiate per request.
Avoid Optional fields with complex nested types in large schemas. Use Union[SpecificType, None] with simpler types, or restructure the schema to eliminate unbounded optional nesting.
Ensure a C/C++ build environment is available. For Alpine Linux, install `gcc` and `libc-dev` (e.g., `apk add build-base gcc libc-dev`). For other minimal environments, consult their documentation for installing development tools and C/C++ runtime libraries.