Quotation marks in API response breaking follow-up responses

I keep getting an error in chat responses when the message content of a previous response contains quotation marks. Is this a JSON limitation or a bug in the ChatGPT API?

Here’s the exact JSON that failed repeatedly:

  "role" : "user", 
  "content" : "You are a master marketing strategist. Suggest a series of social media posts to build interest and excitement about Magai. Magai is a Generative AI app that helps content creators produce content that grows their business. Magai has a gorgeous and easy to use interface that makes creating content fun and easy." 
  "role" : "assistant", 
  "content" : "Thank you for the compliment! Here are some social media posts that I recommend for promoting Magai:

1. Introduce Magai: "Meet Magai, the revolutionary Generative AI app helping content creators grow their business. With its stunning and easy-to-use interface, creating content has never been more fun and easy!"

2. Highlight Magai's features: "Say goodbye to writer's block and repetitive content. Magai's advanced generative AI technology assists content creators in producing fresh and unique content, all with just a few clicks."

3. Showcase Magai's results: "See the difference Magai can make! Our users have seen a significant increase in engagement, followers, and sales, all thanks to the high-quality content created with Magai."

4. Share user reviews: "Don't just take our word for it! See why our users love Magai: 'Magai has completely transformed my content creation process. It's so easy to use and has helped me take my business to the next level.'"

5. Offer a discount: "Ready to experience the power of Magai? Use the promo code MAGAI10 at checkout and save 10% on your subscription today!"

6. Re-share user-generated content: "We love seeing the amazing content you're creating with Magai! Tag us in your posts and we may just feature you on our social media."

7. Highlight Magai's ease of use: "Creating professional-grade content has never been easier. With Magai, the entire content creation process is streamlined, so you can focus on growing your business."

Hope these ideas help you build buzz and generate interest around Magai!" 
  "role" : "user", 
  "content" : "write them in a more casual way." 

The first thing the API produced had quotation marks in it. So I assumed it should have been fine. But do I need to replace these quotation marks with something in each new call?

What language are you using to create the objects? Usually they will automatically escape these characters when saving as JSON.

For example mine saves as

“unitDimensions”: {“height”: " 2" "}


“unitDimensions”: {“height”: “2\u00bd”}

which automatically converts back to "

I’m not sure how to answer that question… I’m using Bubble.io to build this app, and it’s API Connector plugin is what makes the calls.

Whatever language Bubble is using, it isn’t escaping its characters properly. It may be an option in their settings?

I’m not sure how much control you have.

You can either parse the JSON yourself, escaping the characters manually. Or you could try hacking it and putting in a

escaped = f"“”{my_bad_json}“”"

Using python.

1 Like

Got it. I can just have Bubble find/replace the JSON-breaking characters before sending the API call. Only problem I noticed with that is that the response from ChatGPT stops using quotation marks when it previously had. Makes it seem less magically consistent. I guess that’s fine though for now until I can think of a better solution.

I had the same issue. It manifested so:

  1. Doing an API call where the parameter was a string that had quotation marks resulted in an error (“type”: “invalid_request_error”)
  2. Sometimes, doing an API call with a string that had quotation marks would work.

This led me to think there was a possibility that the two quotation marks were not the same, so I checked up their charcodes. As it turns out, I was right.

Quotation marks, although they might look the same, can be different characters. This (“) quotation mark is char code 8220. Notice how it curves. This (") other quotation mark is char 34. Notice its lack of curve.

Char 34 will break your code.

You can check for character codes with simple js.

As it turns out, this is due to how JSON works:

How I solved it: I ran my query params through a workflow to find char 34 and replace it with char 8220.

A better solution: Seeing as you are on Bubble.io, you can use the operator :formatted as JSON-safe to the text before you pass it into the API call.

1 Like