这些问题不仅影响程序解析,还经常导致整个流程中断。起初,我以为只能通过不断调整 Prompt、增加 Retry 机制来曲线救国。但后来读到 Google 出的《Prompt Engineering 白皮书》时,注意到里面提到了一个工具 ——json-repair,用于自动修复 LLM 输出的非法 JSON!它的出现,大大降低了处理这类 Bad Case 的心智负担和代码复杂度。
<primitive> ::= <number> | <string> | <boolean> ; Where: ; <number> is a valid real number expressed in one of a number of given formats ; <string> is a string of valid characters enclosed in quotes ; <boolean> is one of the literal strings 'true', 'false', or 'null' (unquoted)
<container> ::= <object> | <array> <array> ::= '[' [ <json> *(', ' <json>) ] ']' ; A sequence of JSON values separated by commas <object> ::= '{' [ <member> *(', ' <member>) ] '}' ; A sequence of 'members' <member> ::= <string> ': ' <json> ; A pair consisting of a name, and a JSON value