Skip to main content
Best answer

Splitting ChatGPT conversation output doesn't work with parentheses

  • October 15, 2024
  • 3 replies
  • 72 views

Forum|alt.badge.img+1

Hey All,

I’ve been running into this issue for months now and just can’t seem to fix it, it keeps popping up. It’s very frustrating because it makes the output of my zaps unreliable.

I use ChatGPT to extract information from a webpage. By formatting the “Output” like this, it will create two output blocks. Whenever I try to split outputs from a ChatGPT Conversation block, it works very well like shown below -except- when the output has parentheses. Due to the parentheses, the output will cut off.

 

The actual output of the subheadline should say this:

  1. Trip planning made easy and (almost) as fun as travelling itself!

However, due to the parenthesis this becomes the output:

  1. Trip planning made easy and (almost

 

Anyone got an idea how to fix this?

Best answer by Troy TessaloneBest answer by Troy Tessalone

@DaanisAan 

Otherwise, I recommend defining a JSON template for ChatGPT to output that can then be reliably parsed using a Code step.

 

EXAMPLE for email parsing...

Action: ChatGPT - Conversation

Prompt ChatGPT to parse the email and returned the data as structured JSON to then be used in the following JavaScript Code step.

  • You only need to configure the field: User Message
  • Adjust the prompt instructions. (first line)
  • Define your JSON template. (fields you want returned from the parsed data)
  • Map the variable that contains the data to be parsed. (e.g. Email Body)
  • Other fields can be left with their default values.

 

 

CONFIG

 

PROMPT

Parse the contact details from the lead.

Return as fully structured JSON object like this:
{
"NameFirst": "",
"NameLast": "",
"Email": "",
"PhoneNumber": "",
"Company": "",
"Website": "",
"Comments": ""
}

Content: {{CONTENT}}

 

RESULTS

 

Action: Code - Run JavaScript

This Zap step will take the returned JSON from ChatGPT, and convert the JSON into individual data point variables that can be mapped to following Zap steps.

 

Map the Assistant Response Message variable from the ChatGPT step.

 

REFERENCE

https://community.zapier.com/featured-articles-65/parse-raw-json-with-javascript-code-step-16116

 

 

CONFIG

 

CODE

let Lead = inputData.Lead;

Lead = JSON.parse(Lead);

output = [{Lead}];

 

RESULTS

 

 

###

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 30938 replies
  • October 15, 2024

Hi @DaanisAan 

One approach would be to use this Zap action: AI by Zapier - Analyze and Return Data

You can use your ChatGPT API Key.

 


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 30938 replies
  • Answer
  • October 15, 2024

@DaanisAan 

Otherwise, I recommend defining a JSON template for ChatGPT to output that can then be reliably parsed using a Code step.

 

EXAMPLE for email parsing...

Action: ChatGPT - Conversation

Prompt ChatGPT to parse the email and returned the data as structured JSON to then be used in the following JavaScript Code step.

  • You only need to configure the field: User Message
  • Adjust the prompt instructions. (first line)
  • Define your JSON template. (fields you want returned from the parsed data)
  • Map the variable that contains the data to be parsed. (e.g. Email Body)
  • Other fields can be left with their default values.

 

 

CONFIG

 

PROMPT

Parse the contact details from the lead.

Return as fully structured JSON object like this:
{
"NameFirst": "",
"NameLast": "",
"Email": "",
"PhoneNumber": "",
"Company": "",
"Website": "",
"Comments": ""
}

Content: {{CONTENT}}

 

RESULTS

 

Action: Code - Run JavaScript

This Zap step will take the returned JSON from ChatGPT, and convert the JSON into individual data point variables that can be mapped to following Zap steps.

 

Map the Assistant Response Message variable from the ChatGPT step.

 

REFERENCE

https://community.zapier.com/featured-articles-65/parse-raw-json-with-javascript-code-step-16116

 

 

CONFIG

 

CODE

let Lead = inputData.Lead;

Lead = JSON.parse(Lead);

output = [{Lead}];

 

RESULTS

 

 

###


Forum|alt.badge.img+1
  • Author
  • Beginner
  • 10 replies
  • October 16, 2024

Hey, thanks a LOT! Will definitely test this.