← 返回目录

JSON Repair

第 29 / 34 卷日期:

•减少幻觉的可能性

•使其具备关系感知能力

•您将获得数据类型

  • 你能做到的

少样本提示章节中的表 4 展示了如何返回结构化输出的示例。

JSON 修复

虽然以 JSON 格式返回数据具有诸多优势,但也并非没有缺点。JSON 的结构化特性虽然有利于解析和应用,但其所需的标记数量显著多于纯文本,导致处理时间增加和成本上升。此外, JSON 的冗长性很容易耗尽整个输出窗口,当生成因标记限制而突然中断时,这一问题尤为突出。这种截断常常导致 JSON 无效,缺失关键的闭合括号或方括号,使输出无法使用。幸运的是,像 json-repair 库(可在 PyPI 上获取)这样的工具在这些情况下非常宝贵。该库智能地尝试自动修复不完整或格式错误的 JSON 对象,使其成为处理 LLM 生成的 JSON 时的关键助手,尤其是在应对潜在的截断问题时。

全站分卷索引 · 34 卷
  1. 1Introduction
  2. 2Prompt engineering
  3. 3LLM output configuration
  4. 4Sampling controls
  5. 5Top-K and top-P
  6. 6Putting it all together
  7. 7Prompting techniques
  8. 8One-shot & few-shot
  9. 9System, contextual and role prompting
  10. 10System prompting
  11. 11Role prompting
  12. 12Contextual prompting
  13. 13Step-back prompting
  14. 14Chain of Thought (CoT)
  15. 15Self-consistency
  16. 16Tree of Thoughts (ToT)
  17. 17ReAct (reason & act)
  18. 18Automatic Prompt Engineering
  19. 19Code prompting
  20. 20Prompts for explaining code
  21. 21Prompts for translating code
  22. 22Prompts for debugging and reviewing code
  23. 23What about multimodal prompting?
  24. 24Design with simplicity
  25. 25Be specific about the output
  26. 26Control the max token length
  27. 27Experiment with input formats and writing styles
  28. 28Adapt to model updates
  29. 29JSON Repair
  30. 30Working with Schemas
  31. 31Experiment together with other prompt engineers
  32. 32CoT Best practices
  33. 33Summary
  34. 34Endnotes