AGENT SKILL

structured-generation

Design and troubleshoot Outlines constrained-generation output types, generators, backends, and logits processors.

License 许可
Apache-2.0
最近更新
2026-09-03
Stars
★ 351
Forks
27

01 前言 Front Matter

name
structured-generation
license
Apache 2.0
metadata
{ "disco-role": "operating" }
description
Design and troubleshoot Outlines constrained-generation output types, generators, backends, and logits processors.
disable-model-invocation
true

02 资源文件 5

03 SKILL.md 正文

Structured Generation

Use this sub-skill when the task is to make an Outlines model return a specific structure: JSON, a Pydantic/dataclass/TypedDict schema, a Literal/Enum/Choice, a regular expression, or a context-free grammar. It also covers the Generator contract, backend selection, raw-output parsing, batch/stream behavior, and custom logits processors.

Route model setup elsewhere:

  • Local/offline engines, tokenizers, GPU/MPS, and model downloads -> ../local-models/SKILL.md.
  • Hosted/server providers and credentials -> ../remote-providers/SKILL.md.
  • Prompt templates, Application, Chat, images, and workflow orchestration -> ../prompt-workflows/SKILL.md.

Fast Route

  1. Choose the output language. Use Python types for simple data, Literal/Enum/Choice for finite choices, a Pydantic/dataclass/TypedDict/GenSON/JsonSchema for JSON, Regex for a regular language, or CFG for Lark-style grammars.

  2. Pick a compatible model route. Local steerable models compile output types into logits processors. Server/black-box providers support only the structured-output formats their SDK/server exposes.

  3. Call directly or reuse a generator. A model call and a generator call are equivalent in shape:

    response = model(prompt, OutputType, max_new_tokens=200)
    generator = outlines.Generator(model, OutputType)
    response = generator(prompt, max_new_tokens=200)
    
  4. Parse the raw string yourself. Outlines v1 returns text. For Pydantic schemas, call Schema.model_validate_json(response) after generation.

  5. Set the backend only for steerable models. Defaults are JSON schema=outlines_core, regex=outlines_core, CFG=llguidance. Override with backend="llguidance" or backend="xgrammar" only after checking support.

  6. Use a custom processor only with steerable models. Generator(model, processor=processor) is mutually exclusive with output_type; server models raise NotImplementedError for processors.

  7. Validate before generation. Check a JSON schema/regex/grammar against representative samples before spending tokens or running a model.

Load These References

  • references/api-reference.md: constructor signatures, output-type conversion rules, direct model calls, Generator, batch/stream, and parsing contracts.
  • references/backends.md: default and selectable backends, model compatibility, unsupported cases, and logits-processor flow.
  • references/workflows.md: schema-first and regex/CFG iteration patterns, Pydantic parsing, and structured workflow recipes.
  • references/troubleshooting.md: symptoms, causes, and recovery for output-type, backend, parsing, and processor failures.

Bundled Script

Use scripts/validate_structure.py for local, no-model validation of JSON samples against JSON Schema or text samples against a regex before you wire the structure into an Outlines call.

Examples:

python scripts/validate_structure.py json --schema '{"type":"object","required":["name"],"properties":{"name":{"type":"string"}}}' --data '{"name":"Ada"}'
python scripts/validate_structure.py regex --pattern '[0-9]{3}' --text '123'

The script does not import provider clients, download models, or call a network service.

Non-Negotiable Checks

  • Never claim a provider supports regex/CFG just because a local model does. Check provider capability first.
  • Never use backend="outlines_core" for CFG; use llguidance or xgrammar with a compatible steerable model.
  • Never set JsonSchema(..., whitespace_pattern=...) with llguidance or xgrammar; use outlines_core if whitespace control is required.
  • Never execute model output as code while validating structure. Parse JSON, match regex, or validate with a schema.
  • Never tell future agents to open original repository docs/examples/tests; this sub-skill and its bundled references/scripts are the runtime source.

04 同仓库更多 Skills

VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-triton-opt

Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-solve

END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-skill

PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-pattern-fusion

Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-orchestrate

Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.

★ 351
VectorSpaceLab
VectorSpaceLab/AREX-Skill

passnet-feedback

Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).

★ 351