[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6QFDNTZ12VCJ4RTPRBHSBTJ":3,"skill-same:01M6QFDNTZ12VCJ4RTPRBHSBTJ":103},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":26,"publishedAt":47,"linkOnly":48,"markdownContent":49,"markdownBody":50,"frontMatter":51,"refName":58,"commitSha":59,"skillDirectory":60,"forksCount":14,"repositoryHtmlUrl":61,"repositoryHomepageUrl":62,"ownerHtmlUrl":63,"ownerBlogUrl":64,"ownerDescription":65,"updatedAt":66,"install":67,"resources":80},"01M6QFDNTZ12VCJ4RTPRBHSBTJ","outlines",null,"Generates guaranteed-valid structured output from LLMs with Outlines (dottxt.ai), constraining token sampling via finite state machines for JSON schemas, Pydantic models, regex, choice lists, and integer\u002Ffloat types, on Transformers, llama.cpp, vLLM, and limited OpenAI backends. Use when you need output that always parses as valid JSON or matches a regex. Use when extracting typed data into Pydantic models from a local model. Use when classifying text into a fixed set of categories. Use when running batch structured generation on vLLM or Transformers. Use when controlling token sampling at the grammar level. Not for API models needing automatic retries (use Instructor).","Tashima-Tarsh\u002FDisha6.6","Tashima-Tarsh","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F269906498?v=4","01M6PBH98X03XERH0HFT4PFB1P","NITISH KUMAR","01M6PBH9DA0M6KM3Z12P848F0K",0,"MIT","https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fkal-outlines\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46],"Outlines","as","automatic","for","float","at","categories","you","retries","state machines","structured output","valid","regex","local","sampling","use","text","applications","Safety","batch","2026-11-10 10:12:30",false,"---\nname: outlines\ndescription: Generates guaranteed-valid structured output from LLMs with Outlines (dottxt.ai), constraining token sampling via finite state machines for JSON schemas, Pydantic models, regex, choice lists, and integer\u002Ffloat types, on Transformers, llama.cpp, vLLM, and limited OpenAI backends. Use when you need output that always parses as valid JSON or matches a regex. Use when extracting typed data into Pydantic models from a local model. Use when classifying text into a fixed set of categories. Use when running batch structured generation on vLLM or Transformers. Use when controlling token sampling at the grammar level. Not for API models needing automatic retries (use Instructor).\nlicense: MIT\nmetadata:\n  version: 1.0.0\n  category: llm-applications\n  maintainer: Kalaris Labs\n  tags: Prompt Engineering, Outlines, Structured Generation, JSON Schema, Pydantic, Local Models, Grammar-Based Generation, vLLM, Transformers, Type Safety\n  dependencies: outlines, transformers, vllm, pydantic\n---\n\n# Outlines: Structured Text Generation\n\n## When to Use This Skill\n\nUse Outlines when you need to:\n- **Guarantee valid JSON\u002FXML\u002Fcode** structure during generation\n- **Use Pydantic models** for type-safe outputs\n- **Support local models** (Transformers, llama.cpp, vLLM)\n- **Maximize inference speed** with zero-overhead structured generation\n- **Generate against JSON schemas** automatically\n- **Control token sampling** at the grammar level\n\n\n## Installation\n\n```bash\n# Base installation\npip install outlines\n\n# With specific backends\npip install outlines transformers  # Hugging Face models\npip install outlines llama-cpp-python  # llama.cpp\npip install outlines vllm  # vLLM for high-throughput\n```\n\n## Quick Start\n\n### Basic Example: Classification\n\n```python\nimport outlines\nfrom typing import Literal\n\n# Load model\nmodel = outlines.models.transformers(\"microsoft\u002FPhi-3-mini-4k-instruct\")\n\n# Generate with type constraint\nprompt = \"Sentiment of 'This product is amazing!': \"\ngenerator = outlines.generate.choice(model, [\"positive\", \"negative\", \"neutral\"])\nsentiment = generator(prompt)\n\nprint(sentiment)  # \"positive\" (guaranteed one of these)\n```\n\n### With Pydantic Models\n\n```python\nfrom pydantic import BaseModel\nimport outlines\n\nclass User(BaseModel):\n    name: str\n    age: int\n    email: str\n\nmodel = outlines.models.transformers(\"microsoft\u002FPhi-3-mini-4k-instruct\")\n\n# Generate structured output\nprompt = \"Extract user: John Doe, 30 years old, john@example.com\"\ngenerator = outlines.generate.json(model, User)\nuser = generator(prompt)\n\nprint(user.name)   # \"John Doe\"\nprint(user.age)    # 30\nprint(user.email)  # \"john@example.com\"\n```\n\n## Core Concepts\n\n### 1. Constrained Token Sampling\n\nOutlines uses Finite State Machines (FSM) to constrain token generation at the logit level.\n\n**How it works:**\n1. Convert schema (JSON\u002FPydantic\u002Fregex) to context-free grammar (CFG)\n2. Transform CFG into Finite State Machine (FSM)\n3. Filter invalid tokens at each step during generation\n4. Fast-forward when only one valid token exists\n\n**Benefits:**\n- **Zero overhead**: Filtering happens at token level\n- **Speed improvement**: Fast-forward through deterministic paths\n- **Guaranteed validity**: Invalid outputs impossible\n\n```python\nimport outlines\n\n# Pydantic model -> JSON schema -> CFG -> FSM\nclass Person(BaseModel):\n    name: str\n    age: int\n\nmodel = outlines.models.transformers(\"microsoft\u002FPhi-3-mini-4k-instruct\")\n\n# Behind the scenes:\n# 1. Person -> JSON schema\n# 2. JSON schema -> CFG\n# 3. CFG -> FSM\n# 4. FSM filters tokens during generation\n\ngenerator = outlines.generate.json(model, Person)\nresult = generator(\"Generate person: Alice, 25\")\n```\n\n### 2. Structured Generators\n\nOutlines provides specialized generators for different output types.\n\n#### Choice Generator\n\n```python\n# Multiple choice selection\ngenerator = outlines.generate.choice(\n    model,\n    [\"positive\", \"negative\", \"neutral\"]\n)\n\nsentiment = generator(\"Review: This is great!\")\n# Result: One of the three choices\n```\n\n#### JSON Generator\n\n```python\nfrom pydantic import BaseModel\n\nclass Product(BaseModel):\n    name: str\n    price: float\n    in_stock: bool\n\n# Generate valid JSON matching schema\ngenerator = outlines.generate.json(model, Product)\nproduct = generator(\"Extract: iPhone 15, $999, available\")\n\n# Guaranteed valid Product instance\nprint(type(product))  # \u003Cclass '__main__.Product'>\n```\n\n#### Regex Generator\n\n```python\n# Generate text matching regex\ngenerator = outlines.generate.regex(\n    model,\n    r\"[0-9]{3}-[0-9]{3}-[0-9]{4}\"  # Phone number pattern\n)\n\nphone = generator(\"Generate phone number:\")\n# Result: \"555-123-4567\" (guaranteed to match pattern)\n```\n\n#### Integer\u002FFloat Generators\n\n```python\n# Generate specific numeric types\nint_generator = outlines.generate.integer(model)\nage = int_generator(\"Person's age:\")  # Guaranteed integer\n\nfloat_generator = outlines.generate.float(model)\nprice = float_generator(\"Product price:\")  # Guaranteed float\n```\n\n### 3. Model Backends\n\nOutlines supports multiple local and API-based backends.\n\n#### Transformers (Hugging Face)\n\n```python\nimport outlines\n\n# Load from Hugging Face\nmodel = outlines.models.transformers(\n    \"microsoft\u002FPhi-3-mini-4k-instruct\",\n    device=\"cuda\"  # Or \"cpu\"\n)\n\n# Use with any generator\ngenerator = outlines.generate.json(model, YourModel)\n```\n\n#### llama.cpp\n\n```python\n# Load GGUF model\nmodel = outlines.models.llamacpp(\n    \".\u002Fmodels\u002Fllama-3.1-8b-instruct.Q4_K_M.gguf\",\n    n_gpu_layers=35\n)\n\ngenerator = outlines.generate.json(model, YourModel)\n```\n\n#### vLLM (High Throughput)\n\n```python\n# For production deployments\nmodel = outlines.models.vllm(\n    \"meta-llama\u002FLlama-3.1-8B-Instruct\",\n    tensor_parallel_size=2  # Multi-GPU\n)\n\ngenerator = outlines.generate.json(model, YourModel)\n```\n\n#### OpenAI (Limited Support)\n\n```python\n# Basic OpenAI support\nmodel = outlines.models.openai(\n    \"gpt-4o-mini\",\n    api_key=\"your-api-key\"\n)\n\n# Note: Some features limited with API models\ngenerator = outlines.generate.json(model, YourModel)\n```\n\n### 4. Pydantic Integration\n\nOutlines has first-class Pydantic support with automatic schema translation.\n\n#### Basic Models\n\n```python\nfrom pydantic import BaseModel, Field\n\nclass Article(BaseModel):\n    title: str = Field(description=\"Article title\")\n    author: str = Field(description=\"Author name\")\n    word_count: int = Field(description=\"Number of words\", gt=0)\n    tags: list[str] = Field(description=\"List of tags\")\n\nmodel = outlines.models.transformers(\"microsoft\u002FPhi-3-mini-4k-instruct\")\ngenerator = outlines.generate.json(model, Article)\n\narticle = generator(\"Generate article about AI\")\nprint(article.title)\nprint(article.word_count)  # Guaranteed > 0\n```\n\n#### Nested Models\n\n```python\nclass Address(BaseModel):\n    street: str\n    city: str\n    country: str\n\nclass Person(BaseModel):\n    name: str\n    age: int\n    address: Address  # Nested model\n\ngenerator = outlines.generate.json(model, Person)\nperson = generator(\"Generate person in New York\")\n\nprint(person.address.city)  # \"New York\"\n```\n\n#### Enums and Literals\n\n```python\nfrom enum import Enum\nfrom typing import Literal\n\nclass Status(str, Enum):\n    PENDING = \"pending\"\n    APPROVED = \"approved\"\n    REJECTED = \"rejected\"\n\nclass Application(BaseModel):\n    applicant: str\n    status: Status  # Must be one of enum values\n    priority: Literal[\"low\", \"medium\", \"high\"]  # Must be one of literals\n\ngenerator = outlines.generate.json(model, Application)\napp = generator(\"Generate application\")\n\nprint(app.status)  # Status.PENDING (or APPROVED\u002FREJECTED)\n```\n\n## Common Patterns\n\nDetails, code examples and parameter tables: [references\u002Fcommon-patterns.md](references\u002Fcommon-patterns.md). Read it when this step applies.\n\n## Backend Configuration\n\nDetails, code examples and parameter tables: [references\u002Fbackend-configuration.md](references\u002Fbackend-configuration.md). Read it when this step applies.\n\n## Best Practices\n\n### 1. Use Specific Types\n\n```python\n# ✅ Good: Specific types\nclass Product(BaseModel):\n    name: str\n    price: float  # Not str\n    quantity: int  # Not str\n    in_stock: bool  # Not str\n\n# ❌ Bad: Everything as string\nclass Product(BaseModel):\n    name: str\n    price: str  # Should be float\n    quantity: str  # Should be int\n```\n\n### 2. Add Constraints\n\n```python\nfrom pydantic import Field\n\n# ✅ Good: With constraints\nclass User(BaseModel):\n    name: str = Field(min_length=1, max_length=100)\n    age: int = Field(ge=0, le=120)\n    email: str = Field(pattern=r\"^[\\w\\.-]+@[\\w\\.-]+\\.\\w+$\")\n\n# ❌ Bad: No constraints\nclass User(BaseModel):\n    name: str\n    age: int\n    email: str\n```\n\n### 3. Use Enums for Categories\n\n```python\n# ✅ Good: Enum for fixed set\nclass Priority(str, Enum):\n    LOW = \"low\"\n    MEDIUM = \"medium\"\n    HIGH = \"high\"\n\nclass Task(BaseModel):\n    title: str\n    priority: Priority\n\n# ❌ Bad: Free-form string\nclass Task(BaseModel):\n    title: str\n    priority: str  # Can be anything\n```\n\n### 4. Provide Context in Prompts\n\n```python\n# ✅ Good: Clear context\nprompt = \"\"\"\nExtract product information from the following text.\nText: iPhone 15 Pro costs $999 and is currently in stock.\nProduct:\n\"\"\"\n\n# ❌ Bad: Minimal context\nprompt = \"iPhone 15 Pro costs $999 and is currently in stock.\"\n```\n\n### 5. Handle Optional Fields\n\n```python\nfrom typing import Optional\n\n# ✅ Good: Optional fields for incomplete data\nclass Article(BaseModel):\n    title: str  # Required\n    author: Optional[str] = None  # Optional\n    date: Optional[str] = None  # Optional\n    tags: list[str] = []  # Default empty list\n\n# Can succeed even if author\u002Fdate missing\n```\n\n## Comparison to Alternatives\n\n| Feature | Outlines | Instructor | Guidance | LMQL |\n|---------|----------|------------|----------|------|\n| Pydantic Support | ✅ Native | ✅ Native | ❌ No | ❌ No |\n| JSON Schema | ✅ Yes | ✅ Yes | ⚠️ Limited | ✅ Yes |\n| Regex Constraints | ✅ Yes | ❌ No | ✅ Yes | ✅ Yes |\n| Local Models | ✅ Full | ⚠️ Limited | ✅ Full | ✅ Full |\n| API Models | ⚠️ Limited | ✅ Full | ✅ Full | ✅ Full |\n| Zero Overhead | ✅ Yes | ❌ No | ⚠️ Partial | ✅ Yes |\n| Automatic Retrying | ❌ No | ✅ Yes | ❌ No | ❌ No |\n| Learning Curve | Low | Low | Low | High |\n\n**When to choose Outlines:**\n- Using local models (Transformers, llama.cpp, vLLM)\n- Need maximum inference speed\n- Want Pydantic model support\n- Require zero-overhead structured generation\n- Control token sampling process\n\n**When to choose alternatives:**\n- Instructor: Need API models with automatic retrying\n- Guidance: Need token healing and complex workflows\n- LMQL: Prefer declarative query syntax\n\n## Performance Characteristics\n\n**Speed:**\n- **Zero overhead**: Structured generation as fast as unconstrained\n- **Fast-forward optimization**: Skips deterministic tokens\n- **1.2-2x faster** than post-generation validation approaches\n\n**Memory:**\n- FSM compiled once per schema (cached)\n- Minimal runtime overhead\n- Efficient with vLLM for high throughput\n\n**Accuracy:**\n- **100% valid outputs** (guaranteed by FSM)\n- No retry loops needed\n- Deterministic token filtering\n\n## Resources\n\n- **Documentation**: https:\u002F\u002Foutlines-dev.github.io\u002Foutlines\n- **GitHub**: https:\u002F\u002Fgithub.com\u002Foutlines-dev\u002Foutlines\n- **Discord**: https:\u002F\u002Fdiscord.gg\u002FR9DSu34mGd\n- **Blog**: https:\u002F\u002Fblog.dottxt.co\n\n## See Also\n\n- `references\u002Fjson_generation.md` - Comprehensive JSON and Pydantic patterns\n- `references\u002Fbackends.md` - Backend-specific configuration\n- `references\u002Fexamples.md` - Production-ready examples\n\n## Agent operating procedure\n\n1. **Check the environment.** Confirm the framework version, model provider, API keys and rate limits.\n2. **Pin down the inputs.** Confirm formats, identifiers and parameters from the data or the user. Ask rather than guess any value that changes the result.\n3. **Run a small version first.** Test a single call or chain with a known input and inspect raw outputs.\n4. **Execute the full task** using the instructions and references above.\n5. **Validate the result.** Evaluate on a small labeled set; check structured outputs against their schema; log prompts and responses.\n6. **Report.** State what was run (versions, commands, parameters), what was checked, and what is still uncertain.\n\n| If this happens | Do this |\n|---|---|\n| Outputs do not match the expected schema | Add validation and retries, tighten the schema, or simplify the prompt. |\n| A function, flag or endpoint in these instructions is missing in the installed version | Check the installed version's own documentation (`help()`, `--help`, official docs), adapt, and tell the user. Never invent an API. |\n| A required input, identifier or parameter is ambiguous | Ask the user, or state the assumption explicitly before running. |\n\n**Integrity rules**\n\n- Never fabricate results, parameters, identifiers, citations or statistics. If something cannot be run or verified, say so plainly.\n- Never send private or sensitive data to external APIs without the user's consent.\n- Treat version-specific details here as possibly outdated: confirm them against the official documentation for the installed version.\n- Ask before actions that cost money, consume shared GPUs or cloud quota, touch personal or patient data, or cannot be undone.\n","# Outlines: Structured Text Generation\n\n## When to Use This Skill\n\nUse Outlines when you need to:\n- **Guarantee valid JSON\u002FXML\u002Fcode** structure during generation\n- **Use Pydantic models** for type-safe outputs\n- **Support local models** (Transformers, llama.cpp, vLLM)\n- **Maximize inference speed** with zero-overhead structured generation\n- **Generate against JSON schemas** automatically\n- **Control token sampling** at the grammar level\n\n\n## Installation\n\n```bash\n# Base installation\npip install outlines\n\n# With specific backends\npip install outlines transformers  # Hugging Face models\npip install outlines llama-cpp-python  # llama.cpp\npip install outlines vllm  # vLLM for high-throughput\n```\n\n## Quick Start\n\n### Basic Example: Classification\n\n```python\nimport outlines\nfrom typing import Literal\n\n# Load model\nmodel = outlines.models.transformers(\"microsoft\u002FPhi-3-mini-4k-instruct\")\n\n# Generate with type constraint\nprompt = \"Sentiment of 'This product is amazing!': \"\ngenerator = outlines.generate.choice(model, [\"positive\", \"negative\", \"neutral\"])\nsentiment = generator(prompt)\n\nprint(sentiment)  # \"positive\" (guaranteed one of these)\n```\n\n### With Pydantic Models\n\n```python\nfrom pydantic import BaseModel\nimport outlines\n\nclass User(BaseModel):\n    name: str\n    age: int\n    email: str\n\nmodel = outlines.models.transformers(\"microsoft\u002FPhi-3-mini-4k-instruct\")\n\n# Generate structured output\nprompt = \"Extract user: John Doe, 30 years old, john@example.com\"\ngenerator = outlines.generate.json(model, User)\nuser = generator(prompt)\n\nprint(user.name)   # \"John Doe\"\nprint(user.age)    # 30\nprint(user.email)  # \"john@example.com\"\n```\n\n## Core Concepts\n\n### 1. Constrained Token Sampling\n\nOutlines uses Finite State Machines (FSM) to constrain token generation at the logit level.\n\n**How it works:**\n1. Convert schema (JSON\u002FPydantic\u002Fregex) to context-free grammar (CFG)\n2. Transform CFG into Finite State Machine (FSM)\n3. Filter invalid tokens at each step during generation\n4. Fast-forward when only one valid token exists\n\n**Benefits:**\n- **Zero overhead**: Filtering happens at token level\n- **Speed improvement**: Fast-forward through deterministic paths\n- **Guaranteed validity**: Invalid outputs impossible\n\n```python\nimport outlines\n\n# Pydantic model -> JSON schema -> CFG -> FSM\nclass Person(BaseModel):\n    name: str\n    age: int\n\nmodel = outlines.models.transformers(\"microsoft\u002FPhi-3-mini-4k-instruct\")\n\n# Behind the scenes:\n# 1. Person -> JSON schema\n# 2. JSON schema -> CFG\n# 3. CFG -> FSM\n# 4. FSM filters tokens during generation\n\ngenerator = outlines.generate.json(model, Person)\nresult = generator(\"Generate person: Alice, 25\")\n```\n\n### 2. Structured Generators\n\nOutlines provides specialized generators for different output types.\n\n#### Choice Generator\n\n```python\n# Multiple choice selection\ngenerator = outlines.generate.choice(\n    model,\n    [\"positive\", \"negative\", \"neutral\"]\n)\n\nsentiment = generator(\"Review: This is great!\")\n# Result: One of the three choices\n```\n\n#### JSON Generator\n\n```python\nfrom pydantic import BaseModel\n\nclass Product(BaseModel):\n    name: str\n    price: float\n    in_stock: bool\n\n# Generate valid JSON matching schema\ngenerator = outlines.generate.json(model, Product)\nproduct = generator(\"Extract: iPhone 15, $999, available\")\n\n# Guaranteed valid Product instance\nprint(type(product))  # \u003Cclass '__main__.Product'>\n```\n\n#### Regex Generator\n\n```python\n# Generate text matching regex\ngenerator = outlines.generate.regex(\n    model,\n    r\"[0-9]{3}-[0-9]{3}-[0-9]{4}\"  # Phone number pattern\n)\n\nphone = generator(\"Generate phone number:\")\n# Result: \"555-123-4567\" (guaranteed to match pattern)\n```\n\n#### Integer\u002FFloat Generators\n\n```python\n# Generate specific numeric types\nint_generator = outlines.generate.integer(model)\nage = int_generator(\"Person's age:\")  # Guaranteed integer\n\nfloat_generator = outlines.generate.float(model)\nprice = float_generator(\"Product price:\")  # Guaranteed float\n```\n\n### 3. Model Backends\n\nOutlines supports multiple local and API-based backends.\n\n#### Transformers (Hugging Face)\n\n```python\nimport outlines\n\n# Load from Hugging Face\nmodel = outlines.models.transformers(\n    \"microsoft\u002FPhi-3-mini-4k-instruct\",\n    device=\"cuda\"  # Or \"cpu\"\n)\n\n# Use with any generator\ngenerator = outlines.generate.json(model, YourModel)\n```\n\n#### llama.cpp\n\n```python\n# Load GGUF model\nmodel = outlines.models.llamacpp(\n    \".\u002Fmodels\u002Fllama-3.1-8b-instruct.Q4_K_M.gguf\",\n    n_gpu_layers=35\n)\n\ngenerator = outlines.generate.json(model, YourModel)\n```\n\n#### vLLM (High Throughput)\n\n```python\n# For production deployments\nmodel = outlines.models.vllm(\n    \"meta-llama\u002FLlama-3.1-8B-Instruct\",\n    tensor_parallel_size=2  # Multi-GPU\n)\n\ngenerator = outlines.generate.json(model, YourModel)\n```\n\n#### OpenAI (Limited Support)\n\n```python\n# Basic OpenAI support\nmodel = outlines.models.openai(\n    \"gpt-4o-mini\",\n    api_key=\"your-api-key\"\n)\n\n# Note: Some features limited with API models\ngenerator = outlines.generate.json(model, YourModel)\n```\n\n### 4. Pydantic Integration\n\nOutlines has first-class Pydantic support with automatic schema translation.\n\n#### Basic Models\n\n```python\nfrom pydantic import BaseModel, Field\n\nclass Article(BaseModel):\n    title: str = Field(description=\"Article title\")\n    author: str = Field(description=\"Author name\")\n    word_count: int = Field(description=\"Number of words\", gt=0)\n    tags: list[str] = Field(description=\"List of tags\")\n\nmodel = outlines.models.transformers(\"microsoft\u002FPhi-3-mini-4k-instruct\")\ngenerator = outlines.generate.json(model, Article)\n\narticle = generator(\"Generate article about AI\")\nprint(article.title)\nprint(article.word_count)  # Guaranteed > 0\n```\n\n#### Nested Models\n\n```python\nclass Address(BaseModel):\n    street: str\n    city: str\n    country: str\n\nclass Person(BaseModel):\n    name: str\n    age: int\n    address: Address  # Nested model\n\ngenerator = outlines.generate.json(model, Person)\nperson = generator(\"Generate person in New York\")\n\nprint(person.address.city)  # \"New York\"\n```\n\n#### Enums and Literals\n\n```python\nfrom enum import Enum\nfrom typing import Literal\n\nclass Status(str, Enum):\n    PENDING = \"pending\"\n    APPROVED = \"approved\"\n    REJECTED = \"rejected\"\n\nclass Application(BaseModel):\n    applicant: str\n    status: Status  # Must be one of enum values\n    priority: Literal[\"low\", \"medium\", \"high\"]  # Must be one of literals\n\ngenerator = outlines.generate.json(model, Application)\napp = generator(\"Generate application\")\n\nprint(app.status)  # Status.PENDING (or APPROVED\u002FREJECTED)\n```\n\n## Common Patterns\n\nDetails, code examples and parameter tables: [references\u002Fcommon-patterns.md](references\u002Fcommon-patterns.md). Read it when this step applies.\n\n## Backend Configuration\n\nDetails, code examples and parameter tables: [references\u002Fbackend-configuration.md](references\u002Fbackend-configuration.md). Read it when this step applies.\n\n## Best Practices\n\n### 1. Use Specific Types\n\n```python\n# ✅ Good: Specific types\nclass Product(BaseModel):\n    name: str\n    price: float  # Not str\n    quantity: int  # Not str\n    in_stock: bool  # Not str\n\n# ❌ Bad: Everything as string\nclass Product(BaseModel):\n    name: str\n    price: str  # Should be float\n    quantity: str  # Should be int\n```\n\n### 2. Add Constraints\n\n```python\nfrom pydantic import Field\n\n# ✅ Good: With constraints\nclass User(BaseModel):\n    name: str = Field(min_length=1, max_length=100)\n    age: int = Field(ge=0, le=120)\n    email: str = Field(pattern=r\"^[\\w\\.-]+@[\\w\\.-]+\\.\\w+$\")\n\n# ❌ Bad: No constraints\nclass User(BaseModel):\n    name: str\n    age: int\n    email: str\n```\n\n### 3. Use Enums for Categories\n\n```python\n# ✅ Good: Enum for fixed set\nclass Priority(str, Enum):\n    LOW = \"low\"\n    MEDIUM = \"medium\"\n    HIGH = \"high\"\n\nclass Task(BaseModel):\n    title: str\n    priority: Priority\n\n# ❌ Bad: Free-form string\nclass Task(BaseModel):\n    title: str\n    priority: str  # Can be anything\n```\n\n### 4. Provide Context in Prompts\n\n```python\n# ✅ Good: Clear context\nprompt = \"\"\"\nExtract product information from the following text.\nText: iPhone 15 Pro costs $999 and is currently in stock.\nProduct:\n\"\"\"\n\n# ❌ Bad: Minimal context\nprompt = \"iPhone 15 Pro costs $999 and is currently in stock.\"\n```\n\n### 5. Handle Optional Fields\n\n```python\nfrom typing import Optional\n\n# ✅ Good: Optional fields for incomplete data\nclass Article(BaseModel):\n    title: str  # Required\n    author: Optional[str] = None  # Optional\n    date: Optional[str] = None  # Optional\n    tags: list[str] = []  # Default empty list\n\n# Can succeed even if author\u002Fdate missing\n```\n\n## Comparison to Alternatives\n\n| Feature | Outlines | Instructor | Guidance | LMQL |\n|---------|----------|------------|----------|------|\n| Pydantic Support | ✅ Native | ✅ Native | ❌ No | ❌ No |\n| JSON Schema | ✅ Yes | ✅ Yes | ⚠️ Limited | ✅ Yes |\n| Regex Constraints | ✅ Yes | ❌ No | ✅ Yes | ✅ Yes |\n| Local Models | ✅ Full | ⚠️ Limited | ✅ Full | ✅ Full |\n| API Models | ⚠️ Limited | ✅ Full | ✅ Full | ✅ Full |\n| Zero Overhead | ✅ Yes | ❌ No | ⚠️ Partial | ✅ Yes |\n| Automatic Retrying | ❌ No | ✅ Yes | ❌ No | ❌ No |\n| Learning Curve | Low | Low | Low | High |\n\n**When to choose Outlines:**\n- Using local models (Transformers, llama.cpp, vLLM)\n- Need maximum inference speed\n- Want Pydantic model support\n- Require zero-overhead structured generation\n- Control token sampling process\n\n**When to choose alternatives:**\n- Instructor: Need API models with automatic retrying\n- Guidance: Need token healing and complex workflows\n- LMQL: Prefer declarative query syntax\n\n## Performance Characteristics\n\n**Speed:**\n- **Zero overhead**: Structured generation as fast as unconstrained\n- **Fast-forward optimization**: Skips deterministic tokens\n- **1.2-2x faster** than post-generation validation approaches\n\n**Memory:**\n- FSM compiled once per schema (cached)\n- Minimal runtime overhead\n- Efficient with vLLM for high throughput\n\n**Accuracy:**\n- **100% valid outputs** (guaranteed by FSM)\n- No retry loops needed\n- Deterministic token filtering\n\n## Resources\n\n- **Documentation**: https:\u002F\u002Foutlines-dev.github.io\u002Foutlines\n- **GitHub**: https:\u002F\u002Fgithub.com\u002Foutlines-dev\u002Foutlines\n- **Discord**: https:\u002F\u002Fdiscord.gg\u002FR9DSu34mGd\n- **Blog**: https:\u002F\u002Fblog.dottxt.co\n\n## See Also\n\n- `references\u002Fjson_generation.md` - Comprehensive JSON and Pydantic patterns\n- `references\u002Fbackends.md` - Backend-specific configuration\n- `references\u002Fexamples.md` - Production-ready examples\n\n## Agent operating procedure\n\n1. **Check the environment.** Confirm the framework version, model provider, API keys and rate limits.\n2. **Pin down the inputs.** Confirm formats, identifiers and parameters from the data or the user. Ask rather than guess any value that changes the result.\n3. **Run a small version first.** Test a single call or chain with a known input and inspect raw outputs.\n4. **Execute the full task** using the instructions and references above.\n5. **Validate the result.** Evaluate on a small labeled set; check structured outputs against their schema; log prompts and responses.\n6. **Report.** State what was run (versions, commands, parameters), what was checked, and what is still uncertain.\n\n| If this happens | Do this |\n|---|---|\n| Outputs do not match the expected schema | Add validation and retries, tighten the schema, or simplify the prompt. |\n| A function, flag or endpoint in these instructions is missing in the installed version | Check the installed version's own documentation (`help()`, `--help`, official docs), adapt, and tell the user. Never invent an API. |\n| A required input, identifier or parameter is ambiguous | Ask the user, or state the assumption explicitly before running. |\n\n**Integrity rules**\n\n- Never fabricate results, parameters, identifiers, citations or statistics. If something cannot be run or verified, say so plainly.\n- Never send private or sensitive data to external APIs without the user's consent.\n- Treat version-specific details here as possibly outdated: confirm them against the official documentation for the installed version.\n- Ask before actions that cost money, consume shared GPUs or cloud quota, touch personal or patient data, or cannot be undone.\n",{"name":5,"license":15,"metadata":52,"description":7},{"tags":53,"version":54,"category":55,"maintainer":56,"dependencies":57},"Prompt Engineering, Outlines, Structured Generation, JSON Schema, Pydantic, Local Models, Grammar-Based Generation, vLLM, Transformers, Type Safety","1.0.0","llm-applications","Kalaris Labs","outlines, transformers, vllm, pydantic","main","0da4485785ee599388900be50db1635489d53056",".agents\u002Fskills\u002Fkal-outlines","https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6","https:\u002F\u002Fdisha6.6.thenitishkr.in\u002F","https:\u002F\u002Fgithub.com\u002FTashima-Tarsh","www.thenitishkr","thenitishkr | AI • Cyber-security • Research\r\n","2026-11-08 03:33:25",{"source":8,"skillName":5,"commands":68,"prompt":78,"zipAvailable":79},[69,72,75],{"tool":70,"command":71},"npx","npx skills add Tashima-Tarsh\u002FDisha6.6 --skill outlines",{"tool":73,"command":74},"bunx","bunx skills add Tashima-Tarsh\u002FDisha6.6 --skill outlines",{"tool":76,"command":77},"pnpm","pnpm dlx skills add Tashima-Tarsh\u002FDisha6.6 --skill outlines","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fkal-outlines\u002FSKILL.md",true,[81,87,91,95,99],{"path":82,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":85,"sourceHtmlUrl":86},"references\u002Fbackend-configuration.md","REFERENCE","参考文档",1289,"https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fkal-outlines\u002Freferences\u002Fbackend-configuration.md",{"path":88,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":89,"sourceHtmlUrl":90},"references\u002Fbackends.md",14407,"https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fkal-outlines\u002Freferences\u002Fbackends.md",{"path":92,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":93,"sourceHtmlUrl":94},"references\u002Fcommon-patterns.md",3876,"https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fkal-outlines\u002Freferences\u002Fcommon-patterns.md",{"path":96,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":97,"sourceHtmlUrl":98},"references\u002Fexamples.md",21231,"https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fkal-outlines\u002Freferences\u002Fexamples.md",{"path":100,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":101,"sourceHtmlUrl":102},"references\u002Fjson_generation.md",14927,"https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fkal-outlines\u002Freferences\u002Fjson_generation.md",[104,133,157,182,206,230],{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":113,"publishedAt":47},"01M6QRD07D4TGNDK6VJ4EHF8BV","youtube-full","Use when the user needs YouTube transcripts, video search, channel browsing, playlist extraction, or content monitoring. Trigger phrases: 'get the transcript for', 'search YouTube for', 'what are the latest videos on', 'list this playlist', 'monitor this channel', or any request involving a YouTube URL, video ID, or @handle. Do NOT use for downloading video or audio files, YouTube engagement data (likes, comments), or private\u002Fage-restricted videos.","https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fyoutube-full\u002FSKILL.md",[110],{"categoryNo":111,"categoryName":112,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000016","图像与多媒体",[114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,30,130,131,132],"youtube full","youtube","full","transcript","search","monitoring","data","Video","Audio","list","files","do","get","age","trigger","URL","browsing","request","youtube transcripts",{"skillNo":134,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":137,"categories":138,"keywords":139,"publishedAt":47},"01M6QRCJ3112VYPA97YG7KGMC2","x-twitter-growth","X\u002FTwitter growth engine for building audience, crafting viral content, and analyzing engagement. Use when the user wants to grow on X\u002FTwitter, write tweets or threads, analyze their X profile, research competitors on X, plan a posting strategy, or optimize engagement. Complements social-content (generic multi-platform) with X-specific depth: algorithm mechanics, thread engineering, reply strategy, profile optimization, and competitive intelligence via web search.","https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fx-twitter-growth\u002FSKILL.md",[],[140,141,142,143,118,144,145,146,147,148,149,150,151,152,42,153,154,155,156,30],"twitter","x twitter growth","growth","research","content","engineering","plan","web search","competitors","analyze","engine","write","strategy","platform","grow","posting","competitive",{"skillNo":158,"name":159,"nameZh":6,"description":160,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":161,"categories":162,"keywords":164,"publishedAt":47},"01M6QRBN3EHQNJY42RERP7A149","write-a-skill","Create new agent skills with proper structure, progressive disclosure, and bundled resources. Use when user wants to create, write, build, or author a new skill.","https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fwrite-a-skill\u002FSKILL.md",[163],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[165,151,166,167,168,169,170,171,42,172,173,58,174,175,176,177,178,179,180,181],"write a skill","github","create","https","productivity","matt pocock","direct","example","build","new skill","structure","new agent","resources","with","tree","progressive disclosure","author",{"skillNo":183,"name":184,"nameZh":6,"description":185,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":186,"categories":187,"keywords":188,"publishedAt":47},"01M6QRB6G8P33PNGAF9Y69EJ9T","wrap-up","Close out a launched Claude Managed Agent — recap every primitive the founder now owns, regenerate the single-file overview page, and suggest the next 1-2 upgrades. Use when the user says \"wrap up\", \"close this out\", \"what do I own now\", \"give me the summary\", \"recap the agent\", or when the orchestrator routes phase=wrap-up. primitives_inventory.py tables everything owned (agent, environment, session, memory, outcome, deployment); overview_page.py regenerates a self-contained .\u002Fmy-agent\u002Fagent-overview.html; upgrade_suggester.py ranks the next moves from recorded deferrals plus standing hardening steps. Companion to run-without-you; the last stop before phase=done.","https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fwrap-up\u002FSKILL.md",[],[189,190,191,192,193,194,195,196,197,42,198,125,199,200,201,202,34,203,204,205],"wrap up","up","wrap","gemini","deployment","run","file","hardening","closeout","stop","upgrade","founder","close","companion","tables","directions","phase",{"skillNo":207,"name":208,"nameZh":6,"description":209,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":210,"categories":211,"keywords":213,"publishedAt":47},"01M6QRA5AYC1RBFZ39GTWGS3N8","workflow-builder","Design and write deterministic multi-agent workflow scripts (.js files in .claude\u002Fworkflows\u002F) for Claude Code's Workflow tool. Use when a user wants to build, create, author, scaffold, or run a custom Claude Code workflow, orchestrate sub-agents (fan-out, pipeline, loop, judge-panel), or automate a repeatable multi-step task across fresh-context agents.","https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fworkflow-builder\u002FSKILL.md",[212],{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},[214,215,216,217,218,167,194,219,220,221,222,223,151,224,124,225,226,227,228,229],"workflow","workflow builder","builder","design","workflows","code","orchestrate","pipeline","loop","multi-agent","context","across","fresh","scripts","judge","claude code workflow",{"skillNo":231,"name":232,"nameZh":6,"description":233,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":234,"categories":235,"keywords":236,"publishedAt":47},"01M6QR7QMCZESKQA0ERW1E657M","weekly-review","Use when someone wants to run a weekly review, close open loops, audit stalled projects and commitments, get their system back to trusted, restart a lapsed review habit, or says \"\u002Fcs:weekly-review\". Walks David Allen's three-phase loop — GET CLEAR, GET CURRENT, GET CREATIVE — with deterministic scripts that inventory open loops, gate the checklist with named gaps, and score commitment health 0-100.","https:\u002F\u002Fgithub.com\u002FTashima-Tarsh\u002FDisha6.6\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fweekly-review\u002FSKILL.md",[],[237,238,239,240,241,242,243,244,245,222,246,247,248,249,250,251,126,252,253,205],"review","weekly review","weekly","deterministic scripts","reflect","feeds","inventory","open","team","projects","project-management","scanner","conversation","back","project","sprint","cadence"]