The assistant returned "politics" because the user prompt was about politics, but your function schema only accepts a strict enum (business, entertainment, general, health, science, sports, technology). That mismatch causes the downstream API to reject the call. Fix it by (A) normalizing model output before calling your API, (B) updating the enum to match real inputs, or (C) instructing the model to use only allowed values — ideally do A + C for robustness.
Why this happens (brief)
-
Models output semantically useful text (e.g., politics) based on the prompt.
-
JSON enum is a strict contract your downstream code enforces.
-
The model is not a validator — it may produce values outside your enum unless you explicitly constrain it.
Practical fixes (pick and combine)
1) Best practice (recommended): normalize/validate server-side
Node (JS) example:
const allowed = new Set(["business","entertainment","general","health","science","sports","technology"]);
const mapping = { politics: "general", world: "general", gov: "general" };
function normalizeCategory(cat) {
if (!cat) return "general";
cat = String(cat).toLowerCase().trim();
if (allowed.has(cat)) return cat;
return mapping[cat] || "general";
}
// After parsing function_call.arguments:
const rawCat = parsed.function_call?.arguments?.category;
const safeCat = normalizeCategory(rawCat);
// call get_top_headlines_stories with safeCat
Python example:
ALLOWED = {"business","entertainment","general","health","science","sports","technology"}
MAPPING = {"politics":"general","world":"general","gov":"general"}
def normalize_category(cat):
if not cat:
return "general"
cat = str(cat).lower().strip()
if cat in ALLOWED:
return cat
return MAPPING.get(cat, "general")
- If politics genuinely belongs, add it to the enum
Change your function schema so the model and API are aligned:
"enum": ["business","entertainment","general","health","science","sports","technology","politics"]
→ Only do this if your downstream news API actually supports politics.
3) Tell the model which outputs are allowed (system + function description)
Add a system message or augment your function description so the model prefers allowed values.
System message (exact text to copy):
When producing the category argument for get_top_headlines_stories, only return one of: business, entertainment, general, health, science, sports, technology. If the user asks about politics, return general.
Also add a short note in the function description to reinforce it.
4) Defensive JSON schema approach (accept synonyms)
If you want to allow synonyms but still validate, use oneOf/anyOf or accept "category" as string and validate later. Example (looser schema):
"properties": {
"country": {"type":"string", "enum":["de","us","ru","gb","fr","it","es"]},
"category": {"type":"string", "description":"Allowed values: business, entertainment, general, health, science, sports, technology (other values will be normalized)."}
},
"required":["category"]
Use server-side validation to reject/normalize invalid entries.
Handy paste-ready forum reply (short)
The assistant returned "politics" because it interpreted your question literally, but your function schema only allows a fixed enum. Quick options: (1) normalize the model output server-side (map politics → general) before calling your API (recommended), (2) update the enum to include politics if your service supports it, or (3) add a system instruction telling the model to return only allowed enum values. I prefer (1) + (3): always validate model outputs and also instruct the model to respect your allowed values.
Small test checklist
-
Test with prompts: “What’s new in politics?”, “World news”, “Latest in tech”.
-
Confirm your code maps politics → general (or accepts politics if you changed the enum).
-
Log any out-of-enum values so you can expand the mapping if new synonyms appear.