{"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":"python","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,"search_vec":"'0.2.14':53 'activ':60 'ai':77 'align':61 'appear':59 'automata':39 'bind':72 'broader':64 'build':28 'cadenc':57 'capabl':19 'construct':35 'core':3,6,25 'current':50 'effici':41 'express':30 'finit':37 'finite-st':36 'function':26 'generat':18,48,68 'guid':42 'high':14 'high-perform':13 'implement':20 'json':32,73 'languag':44 'larg':43 'librari':10 'llm':46,69 'model':45 'nlp':76 'offer':24 'outlin':2,5,65 'outlines-cor':1,4 'perform':15 'project':66 'provid':12 'python':9,71 'regex':75 'regular':29 'releas':56 'rust':22,70 'schema':33,74 'state':38 'structur':16,67 'text':17 'token':47 'version':51","created_at":"2026-04-09T18:46:46.245813+00:00","updated_at":"2026-04-16T17:50:11.562126+00:00","problems":[{"fix":"Install Rust and Cargo. The recommended way is to use `rustup`: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` (then follow the on-screen instructions), or install via your system's package manager.","cause":"The `outlines-core` library is implemented in Rust and requires a Rust compiler (and Cargo) to be installed on your system to build its native components if a pre-compiled wheel for your specific Python version and operating system is not available.","error":"error: can't find Rust compiler"},{"fix":"Ensure your `outlines` library is up-to-date by running `pip install --upgrade outlines`. If you are using `outlines-core` directly, verify that your code uses the current public API of `outlines-core` or a compatible version of `outlines` that integrates it. Sometimes, if another library has a strict dependency, you might need to install a specific older version, e.g., `pip install outlines==0.0.44`.","cause":"This error typically occurs when there's a version mismatch or breaking API change in the `outlines` library, where modules like `outlines.fsm`, `outlines.caching`, or `outlines._version` have been moved, renamed, or removed in newer versions due to refactoring, especially with the introduction of `outlines-core`.","error":"ModuleNotFoundError: No module named 'outlines.fsm'"},{"fix":"Rename any custom files or modules named `json.py` (or other standard library names) in your project to avoid conflicts with Python's built-in modules. For example, rename `json.py` to `my_json_utils.py`.","cause":"This error arises when a local file or module within your project or environment is named `json.py` (or similar), shadowing Python's standard `json` library, causing import conflicts when `outlines` or its dependencies try to use the built-in `json` module.","error":"AttributeError: partially initialized module 'json' has no attribute 'loads'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.2.14","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/dottxt-ai/outlines-core","docs":"https://dottxt-ai.github.io/outlines-core/","changelog":null,"pypi":"https://pypi.org/project/outlines-core/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["llm-agents","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}