🛠️ Troubleshooting: "Additional text encountered after finished reading JSON content"
If you’ve encountered the error Additional text encountered after finished reading JSON content: . Path '', line 9, position 1, or something similar to this in when using Gemini you are seeing a mismatch between how Gemini is responding and how Zenphi is trying to parse that data.
This usually happens when the model adds extra text before or after the code block, or when the response is cut off mid-sentence.
Here is how to fix it and prevent it from happening again.
1. The Pro-Level Prompting Strategy
If you choose to use the Output as JSON toggle, you must be extremely strict with your System Instructions. Gemini is naturally conversational, so you need to limit its behavior.
Suggested System Instruction:
"Act as a data transformation engine. Your output must be a single, valid JSON object following the schema provided below. Do not include any introductory text, explanations, or Markdown formatting (like ```json). Return only the raw JSON object."
Pro-Tip: Always provide a Sample JSON in your instructions. Giving the model a template reduces the chance of it hallucinating extra fields or formatting the structure incorrectly.
2. The "Set and Forget" Solution: Structured Objects
The most reliable way to avoid this error entirely is to stop manual JSON formatting and use Structured Output.
How to do it: Toggle the Return Structured Object dial in your Zenphi action.
Why it works: You simply define the fields you want Gemini to extract. Zenphi handles the backend communication to ensure the model returns a clean object.
Important: You cannot use "Output as JSON" and "Structured Object" at the same time. If you turn on Structured Objects, remove any "return as JSON" language from your prompt to save on tokens and make sure “Output as JSON” is turned off.
3. Check Your Token Limits (Max Length)
If your JSON is valid but the error still persists, the response might be getting truncated. When the model runs out of "space," it stops mid-character, leaving the JSON "unclosed" and unreadable.
The Fix: Go to Advanced Settings and increase the Maximum Length.
Understanding Tokens: Think of this as your "character budget." One token is roughly 4 characters of standard English text. If you expect a long list of data, ensure your Max Length is high enough to accommodate the entire object.
Maximum Output Limits
Gemini 3.1 Pro & Flash (and Gemini 2.5 Pro/Flash): The absolute maximum value you can set is 65,536 tokens.
(Note: As a general rule of thumb, 100 tokens roughly translate to 60–80 English words. This means unlocking the full 65,536 tokens allows the model to generate roughly 40,000 to 50,000 words in a single request).