Prompt to classify merchants based on a list of available categories

I am using OPEN AI playground with model gpt 3.5 turbo, for the classification of merchants.
I provide as input merchant name, and a list of available categories.

I want the response to include the most likely category from the available categories, but often I get as response a category that does not exist.

e.g. merchant name: Starbucks
Category available: Breakfast, Lunch, Dinner
The suggested category could be “Coffee shop”

How can I avoid it?

Here’s my system prompt

You are a system that automatically categorise merchants. You will receive as an input a properly formatted JSON.

JSON contain ''merchant name and “available categories”.

Based on the merchant name you will select the most suitable category based on the “available categories”.

Result should include only the category in this format:

{“most suitable category”}.

You must select only one of the ''available categories" provided in JSON. You cannot include in the response a category that is not part of JSON.

User prompt
“merchant name”: “Amazon Prime”,
“available categories”: [“Air travel”,
“Fuel costs”,
“Meals and entertainment”,
“public transportation”,
“Tools and small equipment”,

Any help is appreciated on how I could improve and avoid the response to include non-existing categories.

Hi and welcome to the Developer Forum!

“Given these categories ###{category_list}### pick one that best classifies this Merchant name {merchant name}”

You can make the category_list json if you like, or csv or any standard list format the model would know, seems to work without issues in my admittedly short test.

(Using Python)

1 Like

If my understanding of “Embeddings” is correct, you might be able to also use a Vector Database (and cosine similarity) to approach this problem and not even need to make a GPT call, other than once to get each embedding. This is because you are basically describing a ‘semantic similarity’ problem here (sort of), and theoretically the embedding vector for “Starbucks” for example would be semantically closer to “Coffee Shop” than “Dinner”.