Skip to content
Agentmart
Submit a tool

structured-output-json-schema

大模型严格结构化输出 JSON Schema 约束设计与 Function Calling 容错修复机制。

Skill by 2428424081cn

IndexedMIT★ 1
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/2428424081cn-structured-output-json-schema

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

大模型严格结构化输出 JSON Schema 约束设计与 Function Calling 容错修复机制。

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/structured-output-json-schema

What's inside

Skill name
structured-output-json-schema
Description
大模型严格结构化输出 JSON Schema 约束设计与 Function Calling 容错修复机制。
License
MIT
Instructions
35 lines in SKILL.md · view on GitHub

Files (2)

  • SKILL.md
  • skill.json

SKILL.md (first lines)

# 大模型严格结构化 JSON 输出设计准则

## 1. Zod / Pydantic 严格 Schema 约束
定义 Schema 时,必须设置 `additionalProperties: false`,并将所有字段设为 `required`:

```ts
import { z } from 'zod';

export const DecisionResultSchema = z.object({
  status: z.enum(['APPROVED', 'REJECTED', 'NEEDS_REVIEW']),
  confidenceScore: z.number().min(0).max(1),
  reasoning: z.string().min(10).describe('详细决策依据,不少于 10 字'),
  suggestedActions: z.array(z.string()).describe('推荐执行动作清单'),
}).strict();

export type DecisionResult = z.infer<typeof DecisionResultSchema>;
```

## 2. 容错与 JSON 修复流
大模型偶尔会输出包含 Markdown 代码块 (```json ... ```) 或尾随逗号。必须在反序列化层增加清洗容错:

```ts
export function safeParseJson<T>(rawText: string, schema: z.ZodType<T>): T {
  let cleaned = rawText.trim();
  // 去除 markdown 标记
  if (cleaned.startsWith('```json')) cleaned = cleaned.replace(/^```json\s*/, '');
  if (cleaned.startsWith('```')) cleaned = cleaned.replace(/^```\s*/, '');
  if (cleaned.endsWith('```')) cleaned = cleaned.replace(/\s*```$/, '');

  const parsed = JSON.parse(cleaned);
  return schema.parse(parsed);
}
```

From 2428424081cn/Skill-mcp, MIT.

More from 2428424081cn/Skill-mcp

Signals

Stars
1
Forks
0
Open issues
0
Last commit (this folder)
Aug 24, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from 2428424081cn

Cite this page

structured-output-json-schema skill. Agent Mart. https://agentmart.dev/skills/2428424081cn-structured-output-json-schema (last updated 2026-10-24)