Get expert guidance

Technical consultations, custom engineering, and support contracts.

Proxy Structuring Engine

Guaranteed Structured Output from Language Models

Key Features

Perfect Structural Compliance

Enforces your defined structure during generation, eliminating schema violations and parsing errors.

Handles Complexity

Reliably generate intricate nested JSON, valid code, or custom recursive formats using a core state machine engine.

Flexible Structure Definition

Define output structure using Pydantic models, JSON Schema, function signatures, or compose custom constraints directly.

Resilient Generation

Built-in Token Healing recovers from minor tokenization variations. Principled path selection resolves ambiguity.

High-Performance C++ Core

Optimized engine ensures structural correctness with minimal generation overhead (~20ms/token).

Broad Compatibility

Integrates with local LLMs via standard generation hooks. Optional helpers simplify `transformers` use.

The Need for Structure

Large Language Models excel at text generation but fail when specific output structures are required. This inherent unreliability blocks their use in dependable systems.

The Proxy Structuring Engine (PSE) solves this by enforcing structure *during* generation. Its high-performance state machine engine guides the LLM, ensuring the output perfectly matches your requirements.

How It Works

Define Structure - Specify the required output format using Pydantic, JSON Schema, function signatures, or custom state machine composition.

Compile Grammar - PSE translates the structure into an efficient state machine grammar.

Guide Generation - The engine integrates via generation hooks, masking invalid token choices based on the grammar's current state.

Ensure Correctness - The LLM only samples valid tokens. Token Healing adds robustness. The final output is always structurally compliant.

Applications

Reliable AI Agents - Enable agents with dependable tool use and predictable state flow (powers the Proxy Base Agent).

Consistent Data Formatting - Ensure valid JSON, XML, or other structures for APIs and data pipelines.

Accurate Function Calls - Generate perfectly formed arguments for function or API interactions.

Valid Code Generation - Produce syntactically correct code adhering to specified structures.

Benefits

Build Reliably - Create dependable AI systems suitable for production environments.

Increase Efficiency - Eliminate brittle post-processing, validation loops, and retries.

Unlock Potential - Enable complex workflows previously hindered by LLM unpredictability.

Performance

The Proxy Structuring Engine adds minimal overhead while ensuring correctness. Benchmarks demonstrate significant speed advantages over alternative methods.

Generation Time Comparison

Latency Metrics

See our benchmark repository for evaluation code, methodology, and more.

Getting Started

The PSE is currently distributed as a developer SDK on PyPi. Get started in minutes by installing the Python package:

pip install pse

The Python library is open source under the Apache 2.0 license. Check out the examples in the GitHub repository.

Foundation for Reliable Agents

The Proxy Structuring Engine provides the guarantees needed for reliable agentic systems. It powers the Proxy Base Agent, ensuring dependable state transitions and tool use.

Explore the Proxy Base Agent