How to make Chat API guess best choice from given list matching user text

In my app, a user types the description of an event (problem/situation) and I want the AI to offer him the best matching choice from a fixed list of event categories. Each category has a name and a description and there can be a variable amount of them.

I tried using a mix of system and user prompt and tool calls but the AI only seem to consider the first couple of choices given in the list (formatted in JSON).

I’m asking here because maybe there is a good general pattern for prompting this sort requirements.

I find, when having the AI choose between a set number of options, it’s helpful to explicitly tell it how many options there are in the list. So if there are, say, 10 categories, I’ll say: “Please match the user’s input to the best match among the following 10 categories:” - and then give it a numbered list with the categories. I’ve had decent success with this pattern.


Wow, it really improved the matching results.
Thanks a lot!

1 Like