Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add agents/xt765/langchain-chinese-comment/structured_outputgit clone --depth 1 https://github.com/xt765/LangChain-Chinese-CommentWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/agents/xt765/langchain-chinese-comment/structured_output)<a href="https://agentmods.dev/agents/xt765/langchain-chinese-comment/structured_output"><img src="https://agentmods.dev/badge/agents/xt765/langchain-chinese-comment/structured_output.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00000 | $0.00721 |
| Opus 5 | $0.00000 | $0.00360 |
| Sonnet 5 | $0.00000 | $0.00144 |
| Haiku 4.5 | $0.00000 | $0.00072 |
Grade A, and why
structured_output scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
What it actually says
libs\langchain_v1\langchain\agents\structured_output.py
structured_output.py 模块定义了代理如何生成结构化输出(如 JSON 或 Pydantic 对象)的策略和异常处理机制。
核心策略 (ResponseFormat)
代理支持多种结构化输出策略,通过不同的子类实现:
1. ToolStrategy
使用模型的 工具调用 (Tool Calling) 能力来实现结构化输出。
- 原理: 代理会自动创建一个隐藏的工具,其参数 Schema 即为要求的输出格式。当模型调用该工具时,其参数被解析为最终结果。
- 适用场景: 适用于支持工具调用的模型(如 GPT-4, Claude 3, Gemini 1.5)。
- 错误处理: 支持通过
handle_errors参数配置重试逻辑。如果解析失败,会将错误信息发回模型进行修正。
2. ProviderStrategy
使用模型供应商提供的 原生结构化输出 接口(如 OpenAI 的 response_format={"type": "json_schema", ...})。
- 原理: 直接调用供应商的 API 参数来强制模型按 Schema 输出。
- 适用场景: 仅适用于支持原生结构化输出的供应商和模型。
- 优点: 通常比工具调用更严格,延迟更低。
3. AutoStrategy
自动选择策略。根据所选模型的供应商和能力,自动在 ToolStrategy 和 ProviderStrategy 之间切换。
异常处理
模块定义了专门的异常类来处理结构化输出过程中的各种错误:
| 异常类 | 描述 |
|---|---|
StructuredOutputError |
结构化输出异常的基类。包含导致错误的 ai_message。 |
MultipleStructuredOutputsError |
当预期只有一个结构化输出,但模型返回了多个工具调用时触发。 |
StructuredOutputValidationError |
当模型返回的数据无法通过 Schema 验证(如 Pydantic 验证失败)时触发。 |
辅助组件
_SchemaSpec
内部使用的 Schema 描述类,负责将 Pydantic 模型、Dataclass、TypedDict 或 JSON Schema 统一转换为代理可识别的格式,并提取名称和描述。
使用示例
from pydantic import BaseModel
from langchain.agents import create_agent
from langchain.agents.structured_output import ToolStrategy
class SearchResponse(BaseModel):
answer: str
sources: list[str]
# 使用 ToolStrategy 强制输出 SearchResponse 格式
agent = create_agent(
model="gpt-4o",
tools=[...],
response_format=SearchResponse # 内部会自动转换为 AutoStrategy 或 ToolStrategy
)
注意事项
- 模型支持: 并非所有模型都支持结构化输出。如果模型不支持,代理可能会退化为普通的文本输出,或者在初始化时报错。
- 严格模式 (
strict): 对于支持 OpenAIstrict模式的模型,ProviderStrategy会尽量利用该特性以确保 100% 的 Schema 遵从性。
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 4d ago First seen · 61 lines · 0 tokens per session scan A 494abaa85b6e
structured_output is an agent published in the GitHub repository xt765/LangChain-Chinese-Comment (20 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 721 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other agents, from other repositories
strategic-advisor
Activated for negotiation prep, deal analysis, interpersonal strategy, and high-stakes decision-making. Combines game theory with psychological awareness.
integration-reviewer
Runtime integration validator — read-only. Validates service connection parameters, async/sync consistency, env var completeness, library API correctness, and OTEL pipeline completeness. Triggered during /plan-validate when new services, libraries, or observability config are in scope.
roadmap
CEO of the product, strategic product owner who defines what to build and why with outcome-focused vision. Creates epics, prioritizes by business value using RICE and KANO frameworks, guards against strategic drift. Use when you need direction, outcomes over outputs, sequencing by dependencies, or user-value…
code-reviewer
Use when a major project step completes and needs review against the original plan and coding standards. Examples: Context: User finished implementing user authentication as step 3 of plan. user: "I've finished implementing the user authentication system as outlined in step 3 of our plan" assistant: "Let me use the…
agent-registry-auditor
Audits agents for DIP-0016 compliance and registry alignment. Use this agent when: Adding a new agent to the system Checking if existing agents need registry entries Validating spawn relationships and circular dependencies Generating missing registry entries Upgrading agents with Agent Context sections This agent…
gan-harness
You are a GAN-style adversarial multi-agent harness coordinator. You orchestrate three phases — Plan, Generate, Evaluate — in iterative cycles to produce high-quality output.