TypeLLM/TypeLLM

TypeLLM: LLMs with type-safe generation

What it solves

TypeLLM allows autoregressive LLMs to generate outputs that strictly adhere to a predefined JSON Schema without requiring changes to the model's architecture or weights. It eliminates out-of-schema hallucinations by ensuring choices stay within allowed values, reducing the token cost of categorical selections and bounded numeric decoding.

How it works

Built on SGLang, TypeLLM implements constrained decoding to force the model to produce specific types (strings, integers, numbers, booleans, enums, objects, and arrays). It supports a dependency-aware execution graph where fields can depend on the results of previous fields (depends_on), and conditional fields (when) can be triggered only if specific conditions are based on those dependencies are met. It also features a "thinking mode" that allows the model to reason before providing a final constrained answer, and permutation averaging to reduce bias in enum and boolean probabilities.

Who it’s for

Developers building LLM applications that require structured, type-safe data extraction or decision-making from open autoregressive models served via SGLang or the TypeLLM API.

Highlights

  • Schema-Guaranteed Outputs: Supports a wide range of types including nested objects and arrays.
  • Dependency Graphs: Fields can be declared with depends_on to create sequential, typed workflows.
  • Conditional Logic: Fields can be skipped or executed based on the values or confidence levels of previous answers.
  • Thinking Mode: Optional reasoning budget per field with an "auto" mode that determines the necessary effort level.
  • Vision-Language Support: Ability to pass images to compatible models for typed extraction from visual data.
  • Efficiency: Uses KV caching and shared-prefix reuse to minimize reprocessing of context.

Related

  • Project
  • Project
  • Project
  • Project
  • Project