{"id":2176,"library":"outlines-core","title":"Outlines-core","description":"Outlines-core is a Python library that provides high-performance, structured text generation capabilities, implemented in Rust. It offers core functionality for building regular expressions from JSON schemas and constructing finite-state automata to efficiently guide large language model (LLM) token generation. The current version is 0.2.14, with a release cadence that appears active, aligning with the broader 'outlines' project.","status":"active","version":"0.2.14","language":"en","source_language":"en","source_url":"https://github.com/dottxt-ai/outlines-core","tags":["structured generation","LLM","Rust","Python bindings","JSON schema","regex","NLP","AI"],"install":[{"cmd":"pip install outlines-core","lang":"bash","label":"PyPI"}],"dependencies":[],"imports":[{"symbol":"build_regex_from_schema","correct":"from outlines_core.json_schema import build_regex_from_schema"},{"note":"Import path changed significantly in version 0.2 and later. Previously, it was nested under `fsm`.","wrong":"from outlines_core.fsm.guide import Guide","symbol":"Guide","correct":"from outlines_core.guide import Guide"},{"note":"Import path changed significantly in version 0.2 and later. Previously, it was nested under `fsm`.","wrong":"from outlines_core.fsm.guide import Index","symbol":"Index","correct":"from outlines_core.guide import Index"},{"note":"Import path changed significantly in version 0.2 and later. Previously, it was nested under `fsm`.","wrong":"from outlines_core.fsm.guide import Vocabulary","symbol":"Vocabulary","correct":"from outlines_core.guide import Vocabulary"}],"quickstart":{"code":"import json\nfrom outlines_core.json_schema import build_regex_from_schema\nfrom outlines_core.guide import Guide, Index, Vocabulary\n\n# Define a JSON schema\nschema = {\n    \"title\": \"Foo\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"name\": {\"type\": \"string\"},\n        \"age\": {\"type\": \"integer\"}\n    },\n    \"required\": [\"name\", \"age\"]\n}\n\n# Generate a regular expression from the schema\nregex = build_regex_from_schema(json.dumps(schema))\n\n# Create Vocabulary from a pretrained model (e.g., GPT-2 for demonstration)\nvocabulary = Vocabulary.from_pretrained(\"openai-community/gpt2\")\n\n# Create an Index from the regex and vocabulary\nindex = Index(regex, vocabulary)\n\n# Create a Guide instance\nguide = Guide(index)\n\n# Example interaction with the guide (simplified for quickstart)\n# In a real scenario, you'd integrate this with an LLM's token generation\ncurrent_state = guide.get_state()\nallowed_tokens = guide.get_tokens()\nprint(f\"Initial allowed token IDs: {allowed_tokens}\")\n\n# Simulate advancing the guide with a token (e.g., the first allowed token)\nif allowed_tokens:\n    first_token_id = allowed_tokens[0]\n    # In a real LLM integration, you'd feed this token to the model\n    # and then get the next state based on the model's output.\n    next_allowed_tokens = guide.advance(first_token_id)\n    print(f\"Next allowed token IDs after advancing with {first_token_id}: {next_allowed_tokens}\")\n\nprint(f\"Is guide finished? {guide.is_finished()}\")","lang":"python","description":"This quickstart demonstrates how to use `outlines-core` to build a regular expression from a JSON schema, create a vocabulary from a pretrained model, construct an index, and initialize a `Guide` for structured generation. This `Guide` can then be used to constrain the token generation of an LLM."},"warnings":[{"fix":"Update import paths from `outlines_core.fsm.guide` to `outlines_core.guide`. Review the new API for `Guide`, `Index`, and `Vocabulary` as methods and constructors may have changed.","message":"Version 0.2.0 introduced significant interface changes, especially regarding import paths and the API for `Guide`, `Index`, and `Vocabulary`. Code written for `outlines-core` versions prior to 0.2 will likely break.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Ensure Rust is installed and accessible in your system's PATH. On Linux/macOS, use `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`. For specific environments like Docker or CI/CD, ensure the build environment includes Rust.","message":"`outlines-core` requires a Rust compiler to be available on your system during installation if pre-built wheels are not available for your specific Python version and operating system/architecture. This often leads to installation failures in environments like Google Colab or certain ARM-based systems.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that `Vocabulary` is created with string representations of tokens, especially when not using `Vocabulary.from_pretrained()`.","message":"When creating a `Vocabulary` manually from tokenizer data, it's important to convert tokens to their string representations. This is necessary to correctly handle special tokens that might not be recognized by the underlying finite-state automaton (DFA).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}