What is best practice for long list of enums?

I’m wondering what people think of this developer problem - perhaps there is a design pattern for it…

I have a plugin endpoint that expects a string parameter. This value has to be recognized by the backend i.e. it has to be one of the many elements of a long list of accepted values.
The LLM can make reasonable guesses here… but also I know for a fact that (just by the nature of thing) it won’t get it right each time.
The list is too long to spell it out in the OpenAPI descriptor as an enum.

To give an example, my plugin is drawing historical maps of past kingdoms, empires, battles.
The name of the historical country is one of the input parameters.
Often it is provided such that it matches how it is named in the database of historical data… and sometimes it is not.

What is the right thing to do here - in addition to telling the AI that the input parameter could not be interpreted?
In case of history subject what I did is to provide another endpoint where the AI can look up historical countries that existed in the area of a present ay country in the given year. (without the year it would again be too slow and too long to list).

Maybe a version of this approach would work for other cases… i.e. let the AI look up the possible values based on input parameter that is less likely to be misinterpreted.

Does anyone have a better idea?

thanks

If you literally have a list that is too long for the AI to comprehend or to load into context with ridiculous huge context, or too many functions that the AI might potentially call, then your knowledge retrieval API might seem the best way.

Imagine:

function: get_allowed_countries(year)
function: get_historic_battles(country, year_start, year_end)
function: produce_map(year, country, battle)

By having iterative calls, you can continue to put the short answers into the AI function return context, but not continue with the augmentation after it racks up what it needs to know to finally output the desired data. When not overwhelmed with data, it can see what it must emit to the final API.

1 Like