It's always the JSON Parser

Hey guys, I ran into another error parsing data from ChatGPT to the JSON Parser. The error code generated is “Source is not valid JSON.” But, the JSON inside the ChatGPT module is correct. I’ve run it through Claude, ChatGPT, and https://jsonformatter.org/ yet the issue persists. The JSON is extensive and long so posting it here would be a lot.

I’ve also tried using the get variable transformer from the Tools module and the data exists, and even under the error code I get results (please refer to the screenshot):

Any help would be greatly appreciated!

I forgot to add, the goal here is to parse the JSON from the ChatGPT module to then feed to another ChatGPT module that completes “Timelines”. If you have any questions or can assist in anyway, I’d really appreciate it!

Hey Diego,

It seems that there are not enough tokens for this chatGPT response. Look at the end of the JSON - the content is cropped and not closed.

1 Like

Thank you for your reply Mariana,

even when I increase the max tokens up to 2300, the problem still persists.

But is the generated JSON complete as a result?

Have you tried decreasing the max tokens? FOr testing purposes, make it very short so you can see if your process works. The max tokens, if I remember correctly, tells ChatGPT to limit its response to less thant that number of tokens.

Thank you Mariana and L Duperval for taking the time to answer. I made this quick video pertaining to the issue at hand - maybe it’ll provide more context :slight_smile:

HI Diego,

Can you share the input and output bundles? Also, in your JSON parser, I don’t see what it’s trying to use to parse the data. So maybe the input is wrong. Although, from your video, you seem to say that you’ve validated the JSON, so maybe it’s the configuration of the JSON parser.

And I’m interested because I’m in the process of building something similar to what you’re doing.

L

glad to hear you’re building something similar!

What I’m pointing at the JSON parser is the content dynamic variable under the message tab. I’ve also tried the result dynamic variable for the JSON parser to parse through it but the error persists. What’s odd is that despite the error code, if I inject a get variable transformer, there is an output but it can’t be identified.

I think the problem is that the JSON isn’t validated? Please refer to screenshot here:

Hmmm…

Did you see this:

It looks a lot like your problem.

Another one I saw was this:

Where the data is already parsed so you don’t need the JSON parser.

Another option is to create a JSON structure using the output from ChatGPT and using the Generate option in the JSON parser.

L

As you have shown again chatGPT used more than 2300 tokens and it means that answer is incomplete.
image
Give an additional rule to the system prompt: “use no more than n tokens for answer”.
It solved the problem for me:

I could be wrong but I think the max tokens is for the output tokens. Total tokens is a combination of input and output.

From Perplexity:

When discussing the number of tokens in the completion for the ChatGPT API, it specifically refers to the output tokens, not the total tokens (input + output).

Here’s a breakdown of how tokens are counted in the ChatGPT API:

  1. Prompt tokens: These are the tokens used in the input messages, including system, user, and assistant messages[1][3].

  2. Completion tokens: These are the tokens generated by the model in its response[1][3].

  3. Total tokens: This is the sum of prompt tokens and completion tokens[1][3].

The max_tokens parameter in the API request specifically limits the number of completion tokens (output tokens) that the model will generate[2][4]. It does not include the prompt tokens.

For example, if you set max_tokens to 100, the model will generate up to 100 tokens in its response, regardless of how many tokens were in the prompt. However, both prompt and completion tokens count towards the model’s maximum context length[2][4].

It’s important to note that the actual number of completion tokens may be less than the max_tokens value if the model completes its response before reaching the limit[4].

When using the streaming option, the API doesn’t provide token usage information in the streamed response[3]. To calculate token usage in this case, you would need to use a tokenizer (like tiktoken) to count the tokens in both the prompt and the generated response[3].

Citations:
[1] ChatGPT api maximum token - ChatGPT - OpenAI Developer Forum
[2] What is the maximum response length (output tokens) for each GPT model? - API - OpenAI Developer Forum
[3] Reddit - Dive into anything
[4] Can I set max_tokens for chatgpt turbo? - API - OpenAI Developer Forum
[5] openai api - How to calculate the token of the entire ChatGPT conversation? - Stack Overflow

Hey L and Mariana, thank you both. I ended up using both suggestions and the outcome still remains that when I feed “Content” from ChatGPT, the PandaDoc values don’t come up with anything.

The first link you provided L was what I tried first but the JSON parser didn’t pass the data unfortunately. The second option was able to generate the screenshot value but, the output from ChatGPT didn’t appear in the PandaDoc proposal.

Mariana, I did change the system prompt to have it up to 250 tokens. But, unfortunately whether I add a JSON parser in the next step or not, the data isn’t being recognized in the next module.

This ChatGPT module is meant to generate two components for the actual proposal and then generate an AI-generated timeline. But, in testing the output of this JSON parser, there’s nothing that can pass the data to the next module :smiling_face_with_tear:.


Hmmm, weird.

If you’re OK sharing the content of your prompt and your JSON, I can try to reproduce the problem and see if I can find a solution.

At this point, without trying the process and understanding the internal workings, I’m not sure I can offer anything more.

L