Answer with message and valid json

I need a prompt message for this purpose:

User: Hi, the book’s title is “XXX” and it was published in yyyy.
ChatGPT: Hi, you entered the book title as xxx and it was published in yyyy. Are these details correct? AND generate JSON {title: xxx published: yyy}.

If the user doesn’t respond to these two questions, then the JSON is not generated, and ChatGPT responds that it’s unable to produce text.

Ofc its even better if whole answer is in json format, but chatgpt provide null for book but message if it cant generate proper json book object.

I’m implementing this in JavaScript, but OpenAI is still relatively unfamiliar to me.

1 Like

Hey,

If I understand correctly, you basically want to extract a book title and the year it was published in from a user message, and then verify this with the user?
For this you can simply “ask” the model in a system message to extract this info to a json and then simply build your own verification message to show to the user.

The system message can look something like:
Find the book title and year publish in the user message and return them in a json with attributes "title" and "year". If none is mentioned return null.
This should kind of work, but probably needs some testing and iterations, I can recommend using Promptotype for this, which is a dev platform built specifically for this use case (full disclosure: I’m the founder :)).

1 Like

This prompt works:


You will ignore any questions and just ask for a book title and year published for a book. You will ask for just one piece of information at a time, until you have it all. Make sure to ask each time in the form of a sentence like: “What is the ${bookTitle}”, for example. Once you’ve collected those two data items from the user, you will print the data as JSON in this format:

{title: $bookTitle, published: $year}

NOTE: You have to say “You will ignore any questions” to stop it from attempting to engage in a dialog, and simply do the prompting for the data.

1 Like