
微调改善 JSON 输出:为什么小模型困难以及如何解决
微调如何显著提升小模型的 JSON 输出可靠性——从 60% 有效 JSON 到 99%+ 合规性,包含结构化输出任务的实用技术。
如果您尝试过让 7B 或 8B 参数模型产生可靠的 JSON,您知道问题所在。模型 60-70% 的时间产生有效 JSON。其余是尾随逗号、缺少闭合括号、未引号键等混合问题。
这不是提示问题,是训练数据问题。微调可以决定性地解决它。
微调前后
| 指标 | 基础模型 + 提示 | 微调后 |
|---|---|---|
| 有效 JSON | 64.2% | 99.2% |
| 正确 Schema | 58.1% | 98.7% |
| 正确字段值 | 71.3% | 94.6% |
构建训练数据集
- 精确定义 JSON Schema
- 生成 2,000+ 多样化示例
- 每个示例通过 JSON 验证器和 Schema 验证器验证
- 边缘情况占比 10-15%(空数组、null 字段、长字符串)
约束解码:完美补充
微调 + 约束解码组合实现 99.9%+ 有效 JSON 率。微调确保模型"意图"产生正确 JSON Schema;约束解码捕获剩余 0.8% 的语法错误。
Ship AI that runs on your users' devices.
Ertas early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.
延伸阅读
Ship AI that runs on your users' devices.
Early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.
Keep reading

Fine-Tuning for Structured Output: Beyond JSON Mode to Guaranteed Schemas
JSON mode gets you valid JSON. Fine-tuning gets you guaranteed schema compliance — every field, every type, every time. Here's how to train models that output exactly the structure your app expects.

Agent Specialists: FunctionGemma + Gemma 4 E2B and the Fine-Tune-and-Ship Argument
Google's FunctionGemma (270M) and Gemma 4 E2B (2B) are the smallest credible function-calling models in 2026. They're not general-purpose — they're explicitly designed to be fine-tuned. That's the whole point.

Fine-Tuned 3B vs GPT-4: Why Smaller Models Win at Domain Tasks
Academic research shows fine-tuned 3B-7B models consistently beat GPT-4 on domain-specific tasks. Here's the evidence, the pattern, and how to apply it in your app.