I am using json_schema to FORCE a selection from a set of enum choices. It is failing to respond with the set of choices. This makes the model unable to be used for programmatic purposes. I am receiving this error:
{
"error": {
"message": "Generated JSON does not match the expected schema. Please adjust your prompt. See 'failed_generation' for more details. Error: jsonschema: '/choice' does not validate with /properties/choice/enum: value must be \"angry\"",
"type": "invalid_request_error",
"code": "json_validate_failed",
"failed_generation": "{\"choice\":\"happy\"}"
}
}
Here is a reproducible request which commonly make the error pop up.
{
"model": "moonshotai/kimi-k2-instruct-0905",
"messages": [
{
"role": "system",
"content": "Based on the user input, classify the converation with one of the following moods. Return only a single word of the mood that you think classifies the conversation:\n\nangry, bored, confident, dazed, embarrassed, energized, fine, flirty, focused, happy, inspired, playful, sad, scared, tense, uncomfortable"
},
{
"role": "user",
"content": "Rico: Hey hows it going?\nPaka: It's going great! The evening is just starting to pick up, and the energy in here is amazing. What can I get for you tonight?\nRico: Could I get a blue moon?\nPaka: Of course! Coming right up. *He grabs a glass and begins to mix the ingredients together expertly, his hands moving swiftly yet gracefully.* So, Rico, what brings you to The Blue Velvet tonight? Are you here for the live music or just enjoying the ambiance?\nRico: The live music is nice, just enjoying it.\nPaka: I'm glad you're enjoying it. *He slides the perfectly crafted Blue Moon over to Rico with a smile.* Here you go, one Blue Moon just for you. Let me know if you need anything else."
}
],
"max_tokens": 15,
"temperature": 0.6,
"top_p": 0.9,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "thechoice",
"schema": {
"type": "object",
"properties": {
"choice": {
"type": "string",
"description": "The choice",
"enum": [
"angry"
]
}
},
"required": [
"choice"
],
"additionalProperties": false
},
"strict": true
}
}
}
Other providers like openai and vllm when using ‘strict’: true will always select one of these options no matter what.