The documentation for Structured Outputs just says that Enums are supported, but that doesn’t seem to be entirely true. So far I’ve seen the API reject schemas with enum values containing double-quotes and newlines. What is the full set of allowed characters?
This is a question that can be answered by merely sending over five-hundred requests (or 100000+ if you want to find out about all of Unicode), building that many more structured schemas server-side for every one-byte enum. (decode(‘latin1’) to map them, which includes bytes that would be invalid utf-8 start bytes).
This coded task also involves the AI producing without error, which is recorded as true
. By being strict, the API structured schema allows only that enum token (or token sequence) even if the AI couldn’t understand usage.
# Construct the json_schema with the current test_value as the enum
json_schema = {
"name": "ascii_test",
"description": "A basic structured output response schema for an ASCII test with a fixed value",
"strict": True,
"schema": {
"type": "object",
"required": [
"test_value"
],
"properties": {
"test_value": {
"type": "string",
"description": "The value under test which constrains the AI to one possible response",
"enum": [
test_value
]
}
},
"additionalProperties": False
}
}
Look up your character!
Summary
Character | With Escape | Unescaped |
---|---|---|
\x00 | 500 | 500 |
\x01 | true | true |
\x02 | true | true |
\x03 | true | true |
\x04 | true | true |
\x05 | true | true |
\x06 | true | true |
\x07 | true | true |
\x08 | true | true |
\x09 | true | true |
\x0a | 500 | 400 |
\x0b | true | true |
\x0c | true | true |
\x0d | true | true |
\x0e | true | true |
\x0f | true | true |
\x10 | true | true |
\x11 | true | true |
\x12 | true | true |
\x13 | true | true |
\x14 | true | true |
\x15 | true | true |
\x16 | true | true |
\x17 | true | true |
\x18 | true | true |
\x19 | true | true |
\x1a | true | true |
\x1b | true | true |
\x1c | true | true |
\x1d | true | true |
\x1e | true | true |
\x1f | true | true |
’ ’ | true | true |
‘!’ | true | true |
‘"’ | 400 | 400 |
‘#’ | true | true |
‘$’ | true | true |
‘%’ | true | true |
‘&’ | true | true |
‘’’ | true | true |
‘(’ | true | true |
‘)’ | true | true |
‘*’ | true | true |
‘+’ | true | true |
‘,’ | true | true |
‘-’ | true | true |
‘.’ | true | true |
‘/’ | true | true |
‘0’ | true | true |
‘1’ | true | true |
‘2’ | true | true |
‘3’ | true | true |
‘4’ | true | true |
‘5’ | true | true |
‘6’ | true | true |
‘7’ | true | true |
‘8’ | true | true |
‘9’ | true | true |
‘:’ | true | true |
‘;’ | true | true |
‘<’ | true | true |
‘=’ | true | true |
‘>’ | true | true |
‘?’ | true | true |
‘@’ | true | true |
‘A’ | true | true |
‘B’ | true | true |
‘C’ | true | true |
‘D’ | true | true |
‘E’ | true | true |
‘F’ | true | true |
‘G’ | true | true |
‘H’ | true | true |
‘I’ | true | true |
‘J’ | true | true |
‘K’ | true | true |
‘L’ | true | true |
‘M’ | true | true |
‘N’ | true | true |
‘O’ | true | true |
‘P’ | true | true |
‘Q’ | true | true |
‘R’ | true | true |
‘S’ | true | true |
‘T’ | true | true |
‘U’ | true | true |
‘V’ | true | true |
‘W’ | true | true |
‘X’ | true | true |
‘Y’ | true | true |
‘Z’ | true | true |
‘[’ | true | true |
‘\’ | true | 500 |
‘]’ | true | true |
‘^’ | true | true |
‘_’ | true | true |
‘`’ | true | true |
‘a’ | true | true |
‘b’ | true | true |
‘c’ | true | true |
‘d’ | true | true |
‘e’ | true | true |
‘f’ | true | true |
‘g’ | true | true |
‘h’ | true | true |
‘i’ | true | true |
‘j’ | true | true |
‘k’ | true | true |
‘l’ | true | true |
‘m’ | true | true |
‘n’ | true | true |
‘o’ | true | true |
‘p’ | true | true |
‘q’ | true | true |
‘r’ | true | true |
‘s’ | true | true |
‘t’ | true | true |
‘u’ | true | true |
‘v’ | true | true |
‘w’ | true | true |
‘x’ | true | true |
‘y’ | true | true |
‘z’ | true | true |
‘{’ | true | true |
’ | ’ | true |
‘}’ | true | true |
‘~’ | true | true |
\x7f | true | true |
\x80 | true | true |
\x81 | true | true |
\x82 | true | true |
\x83 | true | true |
\x84 | true | true |
\x85 | true | true |
\x86 | true | true |
\x87 | true | true |
\x88 | true | true |
\x89 | true | true |
\x8a | true | true |
\x8b | true | true |
\x8c | true | true |
\x8d | true | true |
\x8e | true | true |
\x8f | true | true |
\x90 | true | true |
\x91 | true | true |
\x92 | true | true |
\x93 | true | true |
\x94 | true | true |
\x95 | true | true |
\x96 | true | true |
\x97 | true | true |
\x98 | true | true |
\x99 | true | true |
\x9a | true | true |
\x9b | true | true |
\x9c | true | true |
\x9d | true | true |
\x9e | true | true |
\x9f | true | true |
\xa0 | true | true |
‘¡’ | true | true |
‘¢’ | true | true |
‘£’ | true | true |
‘¤’ | true | true |
‘¥’ | true | true |
‘¦’ | true | true |
‘§’ | true | true |
‘¨’ | true | true |
‘©’ | true | true |
‘ª’ | true | true |
‘«’ | true | true |
‘¬’ | true | true |
\xad | true | true |
‘®’ | true | true |
‘¯’ | true | true |
‘°’ | true | true |
‘±’ | true | true |
‘²’ | true | true |
‘³’ | true | true |
‘´’ | true | true |
‘µ’ | true | true |
‘¶’ | true | true |
‘·’ | true | true |
‘¸’ | true | true |
‘¹’ | true | true |
‘º’ | true | true |
‘»’ | true | true |
‘¼’ | true | true |
‘½’ | true | true |
‘¾’ | true | true |
‘¿’ | true | true |
‘À’ | true | true |
‘Á’ | true | true |
‘Â’ | true | true |
‘Ã’ | true | true |
‘Ä’ | true | true |
‘Å’ | true | true |
‘Æ’ | true | true |
‘Ç’ | true | true |
‘È’ | true | true |
‘É’ | true | true |
‘Ê’ | true | true |
‘Ë’ | true | true |
‘Ì’ | true | true |
‘Í’ | true | true |
‘Î’ | true | true |
‘Ï’ | true | true |
‘Ð’ | true | true |
‘Ñ’ | true | true |
‘Ò’ | true | true |
‘Ó’ | true | true |
‘Ô’ | true | true |
‘Õ’ | true | true |
‘Ö’ | true | true |
‘×’ | true | true |
‘Ø’ | true | true |
‘Ù’ | true | true |
‘Ú’ | true | true |
‘Û’ | true | true |
‘Ü’ | true | true |
‘Ý’ | true | true |
‘Þ’ | true | true |
‘ß’ | true | true |
‘à’ | true | true |
‘á’ | true | true |
‘â’ | true | true |
‘ã’ | true | true |
‘ä’ | true | true |
‘å’ | true | true |
‘æ’ | true | true |
‘ç’ | true | true |
‘è’ | true | true |
‘é’ | true | true |
‘ê’ | true | true |
‘ë’ | true | true |
‘ì’ | true | true |
‘í’ | true | true |
‘î’ | true | true |
‘ï’ | true | true |
‘ð’ | true | true |
‘ñ’ | true | true |
‘ò’ | true | true |
‘ó’ | true | true |
‘ô’ | true | true |
‘õ’ | true | true |
‘ö’ | true | true |
‘÷’ | true | true |
‘ø’ | true | true |
‘ù’ | true | true |
‘ú’ | true | true |
‘û’ | true | true |
‘ü’ | true | true |
‘ý’ | true | true |
‘þ’ | true | true |
‘ÿ’ | true | true |
Yes, even unprintable bytes:
"content": "{\\"test_value\\":\\"\\u0004\\"}"
The 400 errors:
\" is not allowed in string literals for structured outputs (strict=true)
\n is not allowed in string literals for structured outputs (strict=true)