해리슨 블로그

When JSON Breaks in Gemini (or Other LLMs)

Created: 2024-06-04

Created: 2024-06-04 20:12

When generating JSON from LLMs like Gemini Pro, Flash, and others, the output sometimes contains incorrect characters, leading to corruption.



If you try to parse this with JSON.parse, it will result in an error because there's another " (quotation mark) inside the existing ".

In such cases, consider using YAML.

By requesting the output in YAML format as shown above, you can get a stable output. Then, convert the generated YAML back to JSON.

However, there's one important thing to note here.

If you simply output the value on a separate line, you might still encounter errors due to the " inside another ". Therefore, you need to break it down to the next line.

Add the following prompt:


Comments0