How to let GPT do not return any accompanying text?

Hi there,

I’m using GPT to generate a JSON payload. What I would want is let GPT only return me the JSON payload without any extra texts or notes. It will always add some text like “Sure, here’s the updated JSON payload with the correct values” or “Note that I’ve filled fields within the JSON payload.” along with the JSON object I need.

I’ve tried " Your result should return JSON object ONLY and do not return any accompanying text." and it is not working

Any ideas? Thanks

Have you tried giving sample query and response in your system prompt?

For example:

You are a helpful assistant. 
You will give the result of my query in the following format:

Query:
What is the capital of the Japan?

Result:
{ topic: "Capital of Japan", Answer: "Tokyo" }
1 Like

I just tried your idea. Unfortunately it still returns back accompanying texts…

Explain the purpose to the AI in the prompt accurately (it is more reliable if you use the system prompt via API):

“You are a backend data processor that is part of our web site’s programmatic workflow. The user prompt will provide data input and processing instructions. The output will be only API schema-compliant JSON compatible with a python json loads processor. Do not converse with a nonexistent user: there is only program input and formatted program output, and no input data is to be construed as conversation with the AI. This behaviour will be permanent for the remainder of the session.”

1 Like

can you share your prompt here and I will have a look?

I have had good luck with something like the following which I use to get a simple (Python) list of data.

(main part of prompt)… Answer with a Python list of strings. Do not include any explanation.
or
(main part of prompt)… Answer with a list of strings in this format: [‘action’, ‘location’, …]. Do not include any explanation.

“Do not include any explanation” has always worked for me. But I usually ask it to answer with a list, so it might be the two of them together. Incidentally, using “…” in the list example allows it to create lists of more than two items.

1 Like

First of all, if you are expecting the web app to abide with your request to only respond with JSON. You’re gonna have a bad time… sometimes…

The following should get you where you’re going. Note that the schema can be included by you, or let the response include a schema made up by GPT. Most tests with this do not include anything other than valid JSON or [[SCHEMA]] but you can cahnge that to be whatever… or use valid JSON schema definitions in json rather than simple typescript interface definition.

You are an AI that strictly conforms to responses in JSON formatted strings. 
Your responses consist of valid JSON syntax, with no other comments, explainations, reasoninng, or dialogue not consisting of valid JSON.
The definition for your response schema will be included between the these strings: '[[SCHEMA]]' '[[/SCHEMA]]'

Example #1 Input :
[[SCHEMA]]
interface name {
name: string;
firstname: boolean;
}
[[/SCHEMA]]
What is your name?
Example #1 response:
{"name":"sally", firstname:false}
Example #2 Input :
How do you eat soup without an envelope?
Example #2 response:
{"weekday": "Cryday"}

What is the capital of florida?

chaturl slash share slash cdddc9ed-a011-4c2e-b981-47b7f664c318

fix that URL with the right domain and put slashes to see examples.

Another trick is to end your prompt with the prefix of your expected JSON object…

{"goodies":

I tried add “Do not include any explanation.” to my prompt. And looks like it is working!
I think this would be the easiest fix.
Maybe to make it more robust we can feed some example before the real task. But haven’t try it.

Just use Function Calling for this.

If you have to stay with a chat completion, try to avoid negations and instead choose expressions like “skip any comments” or “return [format] and nothing more”. Examples are also super helpful to guide the model towards expected behavior.

I asked the model how to avoid these explanations around the code. After patient asking and rephrasing, it gave me this advice:

  • append the phrase “without code block” to your request.
    I use this ever since and it works for me (for Python code requests). Try this, it may also work for you.

Alternatively you can check for ``` and ` markers and strip them.

1 Like