Correctly prompting for data formats

I’ve been attempting to use OpenAI’s API (and various models) to generate CSV or Markdown data based on a prompt.

As an example, I’m trying to get some textual data in either CSV or Markdown (to be transformed later) around frictions with shipping certain products to certain countries using a loop of the countries and product categories (i.e. electronics, clothing).

So far I have managed to prompt it so that it brings back a short list of ‘short names’ which is a few words to describe the potential friction and a longer description into CSV format (two columns, with the country and product appended outside of OpenAI). Its not assuming that GPT will be correct, but its basically a starting point to work from later.

The results are mixed however, sometimes it works correctly and the format is correct, other times it tried to add blank rows or add a numbered list.

I can’t find anything online which discusses how to achieve this. Is it possible? If so, is this something prompt engineering can solve?

When trying to prompt GPT to generate output in a specific format, I find that samples work the best. Also, remember to add “Return the output in a csv/Markdown format”. The combination of these two has been working quite well for me.

Try to specify the format in your prompt like this example.

Extract the important entities mentioned in the article below. First extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes

Desired format:

Company names: <comma_separated_list_of_company_names>
People names: -||-
Specific topics: -||-
General themes: -||-

Text: """
{text input here}

Set the context of producing a table, and the column names Like this:
Create a table, with the following columns: Country, Size, Population, MainExport. List top 5 based on Polulation, and present the raw output in csv format.