This is an AI translated post.
Select Language
Summarized by durumis AI
- When generating JSON from LLMs, it is possible that incorrect characters are included, causing the output to break.
- Using YAML, you can output stably and convert it back to JSON to solve this problem.
- When outputting YAML, outputting values on individual lines can still cause errors, so you need to output them on the next line.
When generating JSON from LLMs such as Gemini Pro, Flash, etc., there are cases where the output is broken due to incorrect characters.
In cases like this, when trying to use JSON.parse, it will throw an error because there is another " inside the "(quotation mark).
In such cases, let's try using yaml.
- key : |-
If you request output as yaml like this, it can be output stably, and the output yaml can be converted back to json.
But there is one caveat here.
If you output it as a value on a single line, there can still be " inside the ", so you need to change it to the next line.
Add the following prompt.