Yeachan-Heo/oh-my-codex · error
selected value is not in the option schema: ${value}
Error message
selected value is not in the option schema: ${value} What it means
When deriving expected labels for submitted selected_values, each value must either match an option's value in the question schema or (when allow_other is set) equal the trimmed other_text. Any other value throws — the submitted value simply does not exist in the option schema.
Source
Thrown at src/question/state.ts:321
function assertNoDuplicateValues(values: string[], path: string): void {
const seen = new Set<string>();
for (const value of values) {
if (seen.has(value)) throw new Error(`${path} must not contain duplicate values: ${value}`);
seen.add(value);
}
}
function expectedSelectedLabelsForValues(
question: NormalizedQuestionItem,
selectedValues: string[],
otherText: string | undefined,
): string[] {
const optionLabelsByValue = new Map(question.options.map((option) => [option.value, option.label]));
return selectedValues.map((value) => {
const optionLabel = optionLabelsByValue.get(value);
if (optionLabel) return optionLabel;
if (question.allow_other && otherText && value === otherText) return question.other_label;
throw new Error(`selected value is not in the option schema: ${value}`);
});
}
function assertSelectedLabelsMatch(
selectedLabels: string[],
expectedLabels: string[],
path: string,
): void {
if (selectedLabels.length !== expectedLabels.length) {
throw new Error(`${path} cardinality must match selected values`);
}
const mismatchIndex = selectedLabels.findIndex((label, index) => label !== expectedLabels[index]);
if (mismatchIndex !== -1) {
throw new Error(`${path}[${mismatchIndex}] must match the selected value label`);
}
}
function questionForAnswer(record: QuestionRecord, entry: QuestionAnswerEntry): NormalizedQuestionItem {View on GitHub (pinned to 3ad79a8a6f)
Solutions
- Submit option.value (not label) exactly as defined in the question schema
- If sending free text, verify question.allow_other is true and pass the same string as other_text, selected_values[0], and value
- Refresh the question schema before submit if options may have changed
Example fix
// before answer.selected_values = ['Yes please']; // label, not value // after answer.selected_values = [question.options.find((o) => o.label === 'Yes please')!.value]; // 'yes'
Defensive patterns
Strategy: validation
Validate before calling
const known = new Set(question.options.map((o) => o.value));
const ok = answer.selected_values.every((v) => known.has(v) || (question.allow_other && v === answer.other_text?.trim()));
if (!ok) throw new Error('value not in option schema'); Type guard
function valueAllowed(q: NormalizedQuestionItem, v: string, otherText?: string): boolean {
return q.options.some((o) => o.value === v) || (!!q.allow_other && v === otherText?.trim());
} Try / catch
try { await submit(p, answers); } catch (e) { if (/selected value is not in the option schema/.test((e as Error).message)) { await refreshQuestionAndRemap(); return; } throw e; } Prevention
- Always submit option.value, never the label
- Re-validate against a freshly fetched question schema before submit
When it happens
Trigger: Submitting a value not present in question.options[].value and not equal to other_text when allow_other is true; e.g. sending a label instead of a value, or free text without allow_other.
Common situations: Confusing option label with option value (submitting 'Yes please' when value is 'yes'); stale client holding an old question schema after options changed server-side; sending other text on a question with allow_other disabled.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- ${path} must be a non-empty string array
- ${path} cardinality must match selected values
- ${path}[${mismatchIndex}] must match the selected value labe
- answers[${entry.index}].question_id is unknown for this ques
- answers[${entry.index}].answer.kind=other is not allowed for
AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27).
Data as JSON: /api/errors/f8f8e2da46e48773.
Report an issue: GitHub.