# 结构化输出

结构化输出是一种产品模式，而不是某个专用的 AnyInt 端点。确切机制取决于你选择的兼容性家族和模型。

## 推荐方法

1. 先定义你需要的 schema
2. 明确告诉模型要返回哪些键和类型
3. 在你的应用中验证返回的 JSON
4. 为格式错误的输出保留修复或重试路径

## 适用场景

* 信息提取流水线
* 工作流编排
* 代理状态交接
* 表单或 UI 生成

## 跨家族指导

| 家族           | 推荐模式                                       |
| ------------ | ------------------------------------------ |
| 兼容 OpenAI    | 要求严格的 JSON 对象，并在服务器端进行验证                   |
| 兼容 Anthropic | 以文本块形式返回 JSON，并在解析后进行验证                    |
| 兼容 Gemini    | 保持 `contents[].parts[]` 简单，并要求仅返回 JSON 的答案 |

## 示例提示模式

```json
{
  "task": "extract_invoice",
  "fields": {
    "invoice_number": "string",
    "currency": "string",
    "total": "number"
  }
}
```

使用一个明确说明以下内容的提示：

* 仅返回有效的 JSON
* 不要添加 Markdown 代码围栏
* 不要添加解释性文本

## 重要说明

对严格 JSON 控制的支持可能因模型而异。请用你计划在生产环境中运行的具体模型 ID 确认其行为，然后在你这边强制执行 schema 验证。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anyint.gitbook.io/docs/zh/gong-neng/jie-gou-hua-shu-chu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
