Correctly categorizing products into an existing tree of categories

Hello! I’ve read through a whole bunch of existing topics but I can’t find one that corresponds enough with my specific problem. So I’m hoping to get some help here.

Problem:
We have an existing category tree (with roughly 700 product categories, that will increase as time goes on) and many, many products.
What I want is to create a prompt that will take a list of uncategorized products and suggest the most fitting one, in our existing category tree. It doesn’t have to do the actual task of putting them in categories (that would be neat, though) but just suggest the best category for each product based on product name, so I can categorize everything afterwards.

We’ve tried giving the tree as an excel file, we’ve tried writing the entire list in the prompt, we’ve tried giving very detailed instructions about what we want to be done. But one main problem keeps ruining everything no matter what we do:

IT KEEPS SUGGESTING IT’S OWN CATEGORIES THAT DO NOT EXIST IN OUT TREE.

This is incredibly frustrating and I’m honestly all out of ideas. I have no idea why this keeps happening, but it does.

So any and all suggestions tips or complete solutions for this problem would be greatly appreciated. Because it seems simple enough in theory.

1: Existing Categories
2: New Products
Put 2 into 1.

Thank you in advance.

2 Likes

Hi @RoobySwoopy and welcome to the community!

Are you using API or ChatGPT? With ChatGPT I don’t think it’s possible - there is simply not enough control for you to steer it exactly how you would like.

If using API, then one way is to use structured outputs with enum. Enums ensure that only those categories you specified will be selected.

The main issue however is that there is a size limitation on how many enums you can have (500 at the moment). So you need to be bit more clever about engineering this. One way is to have a two-level hierarchy for your product categories - and have a schema with enums for each level. It depends on how your product taxonomy looks like.

But short answer - ChatGPT will not let you do this, but with API structured outputs + enums you can, but need to think a bit in terms of how you overcome the size limitation.

1 Like

Hi! Thank you!

I’m using ChatGPT 4o.

Aha, okay, so it’s not possible in Chat? I’ll look into the API then. Thank you so much :slight_smile:

1 Like