/agentsop-structured-output-picker
Decide where to enforce structured LM output (constrain at decode time with Outlines vs validate-and-retry with Instructor vs grammar with Guidance) and which failure stance to take (Assert/hard-fail vs Suggest/soft-retry). Use when an LM's output is parsed or typed by
$ npx -y skills add agentsope/SkillAlchemy --skill agentsop-structured-output-picker --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/agentsop-structured-output-picker
Context preview
The summary Claude sees to decide when to auto-load this skill.
Decide where to enforce structured LM output (constrain at decode time with Outlines vs validate-and-retry with Instructor vs grammar with Guidance) and which failure stance to take (Assert/hard-fail vs Suggest/soft-retry). Use when an LM's output is parsed or typed by
SKILL.md
agentsop-structured-output-picker.SKILL.mdname: agentsop-structured-output-picker
version: 0.1.0
description: >-
Decide where to enforce structured LM output (constrain at decode time with Outlines vs validate-and-retry with Instructor vs grammar with Guidance) and which failure stance to take (Assert/hard-fail vs Suggest/soft-retry). Use when an LM's output is parsed or typed by downstream code and you must pick one enforcement library plus its failure handling, when malformed output is burning tokens on retries, or when choosing between decode-time vs validation-time constraints for local vs API models.
domain: choosing and configuring a structured-output enforcement layer when LM output is consumed by code
overlay: true
enhances: [outlines, instructor, guidance]
source: |
Local lib skills outlines / instructor / guidance (frontmatter + "When to Use");
DSPy Assert/Suggest constraint primitives (dspy-sop-skill, arXiv 2312.13382);
sibling Phase-D skill output-format-by-model (cross-link, not duplicate);
provider docs for OpenAI structured outputs + Anthropic tool_use.
audience: |
Coder-agents and pipeline authors wiring an LM whose output is parsed/typed by
downstream code; anyone who has outlines / instructor / guidance installed and
must pick one + decide failure handling.
status: tool-skill
Structured-Output-Picker — 在解码处约束,还是在校验处约束?
> **One-liner**: Three local libraries (Outlines, Instructor, Guidance) plus > provider-native structured outputs all "make the model emit valid structure", > but they enforce at *different points* and *fail differently*. Pick by **how > costly a malformed output is** and **whether you control the decoder**. Then > pick the failure stance — **Assert** (hard-fail + retry) vs **Suggest** (soft > nudge, degrade gracefully) — borrowed from DSPy's constraint primitives.
This is an **ENHANCE overlay**. The four enforcement mechanisms each have a working local skill; what no single one provides is the cross-library *which-one
- how-to-handle-failure* decision. That gap is hit every time an LM output is
consumed by code. For **what shape the content should take** (code vs JSON vs prose), descend first to `[[agentsop-output-format-by-model]]` — this skill assumes the shape is already chosen and asks only **how to enforce it**.
---
1. 何时激活 (When to activate)
Activate **after** you have decided the output *shape* (via `[[agentsop-output-format-by-model]]`) and the answer was "a typed/validated object", and **before** you write the parsing code.
| Trigger | Signal | |---|---| | LM output feeds a parser | `json.loads(resp)` / `Model.model_validate(...)` is in the next line of code | | You picked a typed shape | format-by-model said "JSON / Pydantic / typed field" — now: who enforces it? | | Repeated parse failures | `JSONDecodeError`, `ValidationError`, truncated/extra-prose responses in logs | | Library is already installed | `outlines`, `instructor`, or `guidance` is in the env and you must choose between them | | An enum / regex / range must hold | output must be one of N labels, a valid date, a bounded int | | You must decide failure stance | "if the model returns garbage, do I crash, retry, or accept-and-flag?" |
**Anti-triggers** (skip this skill):
- The content is **code / multi-step reasoning / long prose** — go back to
`[[agentsop-output-format-by-model]]`; enforcing a JSON grammar on code is the headline anti-pattern there (Aider 61%→20%). Enforcement strength is the wrong question when the *shape* is wrong.
- No code consumes the output yet (one-shot exploration).
- The shape is one token / one number — any parser works; no library needed.
---
2. 核心心智模型 (Core mental model)
2.1 The axis: where is the constraint applied?
PROMPT ──────► DECODE ──────► RAW TEXT ──────► VALIDATE ──────► TYPED OBJECT
│ │ │
│ constraint at DECODE constraint at VALIDATE
│ (grammar masks tokens) (parse, check, retry on fail)
│ │ │
ask nicely Outlines / Guidance / Instructor / DSPy Suggest /
(weakest) provider strict-mode hand-rolled retry loop
↑ ↑
CANNOT emit invalid CAN emit invalid, then
structure — masked at catches it and re-asks
the logit level with the error injected**The pick is governed by one question: how costly is a malformed output?**
- **A malformed output is cheap to recover from** (one extra API round-trip is
fine; the model is strong; failures are rare) → **constrain at validate** (Instructor-style retry). Simpler, model writes more naturally, no decoder access needed.
- **A malformed output is expensive or impossible to recover from** (no retry
budget, hard real-time, the output *must* be in a fixed enum/grammar, a single bad token corrupts a batch job) → **constrain at decode** (Outlines / Guidance grammar, or provider strict-mode). The model *cannot* emit invalid structure.
2.2 Two prerequisites that gate the choice
1. **Do you control the decoder?** Grammar/token-masking (Outlines, Guidance) requires logit access — i.e. **local/open weights** (Transformers, vLLM, llama.cpp) [[outlines]] [[guidance]]. Closed API models (GPT, Claude) expose only *their own* native structured-output / tool_use; you cannot bolt Outlines onto them. Instructor works *on top of* the API by parse-and-retry [[instructor]]. 2. **Is the content code-shaped?** If yes, stop — see §1 anti-triggers and `[[agentsop-output-format-by-model]]`. Grammar-constraining code yields *valid JSON containing degraded code*: enforcement cannot buy back content quality.
2.3 Failure stance is orthogonal — Assert vs Suggest
Independent of *which* library, you choose what happens on a constraint violation. DSPy names the two stances [dspy-so
Read more
name: agentsop-structured-output-picker version: 0.1.0 description: >- Decide where to enforce structured LM output (constrain at decode time with Outlines vs validate-and-retry with Instructor vs grammar with Guidance) and which failure stance to take (Assert/hard-fail vs Suggest/soft-retry). Use when an LM's output is parsed or typed by downstream code and you must pick one enforcement library plus its failure handling, when malformed output is burning tokens on retries, or when choosing between decode-time vs validation-time constraints for local vs API models. domain: choosing and configuring a structured-output enforcement layer when LM output is consumed by code overlay: true enhances: [outlines, instructor, guidance] source: | Local lib skills outlines / instructor / guidance (frontmatter + "When to Use"); DSPy Assert/Suggest constraint primitives (dspy-sop-skill, arXiv 2312.13382); sibling Phase-D skill output-format-by-model (cross-link, not duplicate); provider docs for OpenAI structured outputs + Anthropic tool_use. audience: | Coder-agents and pipeline authors wiring an LM whose output is parsed/typed by downstream code; anyone who has outlines / instructor / guidance installed and must pick one + decide failure handling. status: tool-skill
Structured-Output-Picker — 在解码处约束,还是在校验处约束?
> **One-liner**: Three local libraries (Outlines, Instructor, Guidance) plus > provider-native structured outputs all "make the model emit valid structure", > but they enforce at *different points* and *fail differently*. Pick by **how > costly a malformed output is** and **whether you control the decoder**. Then > pick the failure stance — **Assert** (hard-fail + retry) vs **Suggest** (soft > nudge, degrade gracefully) — borrowed from DSPy's constraint primitives.
This is an **ENHANCE overlay**. The four enforcement mechanisms each have a working local skill; what no single one provides is the cross-library *which-one
- how-to-handle-failure* decision. That gap is hit every time an LM output is
consumed by code. For **what shape the content should take** (code vs JSON vs prose), descend first to `[[agentsop-output-format-by-model]]` — this skill assumes the shape is already chosen and asks only **how to enforce it**.
---
1. 何时激活 (When to activate)
Activate **after** you have decided the output *shape* (via `[[agentsop-output-format-by-model]]`) and the answer was "a typed/validated object", and **before** you write the parsing code.
| Trigger | Signal | |---|---| | LM output feeds a parser | `json.loads(resp)` / `Model.model_validate(...)` is in the next line of code | | You picked a typed shape | format-by-model said "JSON / Pydantic / typed field" — now: who enforces it? | | Repeated parse failures | `JSONDecodeError`, `ValidationError`, truncated/extra-prose responses in logs | | Library is already installed | `outlines`, `instructor`, or `guidance` is in the env and you must choose between them | | An enum / regex / range must hold | output must be one of N labels, a valid date, a bounded int | | You must decide failure stance | "if the model returns garbage, do I crash, retry, or accept-and-flag?" |
**Anti-triggers** (skip this skill):
- The content is **code / multi-step reasoning / long prose** — go back to
`[[agentsop-output-format-by-model]]`; enforcing a JSON grammar on code is the headline anti-pattern there (Aider 61%→20%). Enforcement strength is the wrong question when the *shape* is wrong.
- No code consumes the output yet (one-shot exploration).
- The shape is one token / one number — any parser works; no library needed.
---
2. 核心心智模型 (Core mental model)
2.1 The axis: where is the constraint applied?
PROMPT ──────► DECODE ──────► RAW TEXT ──────► VALIDATE ──────► TYPED OBJECT
│ │ │
│ constraint at DECODE constraint at VALIDATE
│ (grammar masks tokens) (parse, check, retry on fail)
│ │ │
ask nicely Outlines / Guidance / Instructor / DSPy Suggest /
(weakest) provider strict-mode hand-rolled retry loop
↑ ↑
CANNOT emit invalid CAN emit invalid, then
structure — masked at catches it and re-asks
the logit level with the error injected**The pick is governed by one question: how costly is a malformed output?**
- **A malformed output is cheap to recover from** (one extra API round-trip is
fine; the model is strong; failures are rare) → **constrain at validate** (Instructor-style retry). Simpler, model writes more naturally, no decoder access needed.
- **A malformed output is expensive or impossible to recover from** (no retry
budget, hard real-time, the output *must* be in a fixed enum/grammar, a single bad token corrupts a batch job) → **constrain at decode** (Outlines / Guidance grammar, or provider strict-mode). The model *cannot* emit invalid structure.
2.2 Two prerequisites that gate the choice
1. **Do you control the decoder?** Grammar/token-masking (Outlines, Guidance) requires logit access — i.e. **local/open weights** (Transformers, vLLM, llama.cpp) [[outlines]] [[guidance]]. Closed API models (GPT, Claude) expose only *their own* native structured-output / tool_use; you cannot bolt Outlines onto them. Instructor works *on top of* the API by parse-and-retry [[instructor]]. 2. **Is the content code-shaped?** If yes, stop — see §1 anti-triggers and `[[agentsop-output-format-by-model]]`. Grammar-constraining code yields *valid JSON containing degraded code*: enforcement cannot buy back content quality.
2.3 Failure stance is orthogonal — Assert vs Suggest
Independent of *which* library, you choose what happens on a constraint violation. DSPy names the two stances [dspy-so
Other skills on skillalchemy.
- /LEAP
LEAP — 落地执行引擎。内含两条管线:A 分支蒸馏(从 raw data 提取 skill)、 B 分支融合(多 skill 编织为一个)。被 SkillAlchemy 编排器调用。 Use when 编排器判断需要蒸馏或融合时。
Open skill - /Lens
Lens — 给你的问题加一层认知镜片。输入任意任务描述,输出增强版 description, 发现「你不知道自己不知道」的隐性维度、前置条件和认知路线。 Use when 用户说「帮我想想」「分析一下」「生成 skill」「蒸馏」「融合」 或输入看起来太简单需要展开。
Open skill - /agentsop-agent-topology-selection
Cross-framework enhancement overlay for choosing a multi-agent topology BEFORE writing any agent. A binary-question rubric — is single-agent + tools enough? do agents need to know about each other? does the output need one voice? — maps the answer to single-agent / supervisor /
Open skill - /agentsop-aider
SOP for terminal-based, git-native AI pair programming with Aider (git work-tree + tree-sitter repo-map + edit-format + human-in-loop REPL). Use when editing code in an existing git repo via an LLM, when you need to converge a change to 2-5 files, pick an edit format that fits
Open skill - /agentsop-bio-fraud-forensics
Screens biomedical / life-science papers for signs of data fabrication, image manipulation, and statistical anomalies, using the detection techniques distilled from the field's canonical exposure platforms (PubPeer, Data Colada, Science Integrity Digest, For Better Science) and
Open skill - /agentsop-bounded-loop
Universal discipline for any LM-driven loop — agent retries, plan-act-observe, multi-agent handoffs, optimiser passes, test-fix cycles. Encodes the one rule every framework documents quietly and every team relearns expensively: the LM in the loop is NEVER a reliable terminator.
Open skill

