Yeachan-Heo/oh-my-codex · error · Error

question_invalid_answer

question_invalid_answer

Error message

answers[${entry.index}].answer selected value is not in the option schema: ${selectedValue}

What it means

For option-kind answers the single selected value must be one of the question's option values. This is the single-select counterpart of the schema membership check and carries code question_invalid_answer.

Source

Thrown at src/question/state.ts:391

    if (selectedValues.length !== 1 || selectedValues[0] !== otherText || answer.value !== otherText) {
      throw new Error(`answers[${entry.index}].answer other value must match selected_values[0] and other_text`);
    }
    assertSelectedLabelsMatch(
      selectedLabels,
      [question.other_label],
      `answers[${entry.index}].answer.selected_labels`,
    );
    return;
  }

  if (answer.kind === 'option') {
    if (multi) throw new Error(`answers[${entry.index}].answer.kind=option is only valid for single-answerable questions`);
    if (selectedValues.length !== 1 || selectedLabels.length !== 1) {
      throw new Error(`answers[${entry.index}].answer must select exactly one option`);
    }
    const selectedValue = selectedValues[0]!;
    if (!optionValues.has(selectedValue)) {
      throw new Error(`answers[${entry.index}].answer selected value is not in the option schema: ${selectedValue}`);
    }
    if (answer.value !== selectedValue) {
      throw new Error(`answers[${entry.index}].answer.value must match selected_values[0]`);
    }
    assertSelectedLabelsMatch(
      selectedLabels,
      expectedSelectedLabelsForValues(question, selectedValues, undefined),
      `answers[${entry.index}].answer.selected_labels`,
    );
    return;
  }

  if (!multi) throw new Error(`answers[${entry.index}].answer.kind=multi is only valid for multi-answerable questions`);
  if (!Array.isArray(answer.value)) throw new Error(`answers[${entry.index}].answer.value must be an array for multi answers`);
  if (answer.value.length !== selectedValues.length || answer.value.some((value, index) => value !== selectedValues[index])) {
    throw new Error(`answers[${entry.index}].answer.value must match selected_values`);
  }
  if (outOfSchemaValues.length > 0) {

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Map UI choice to question.options[].value before submit
  2. Refresh the question schema if options may have changed since render

Example fix

// before
answer.selected_values = [selectedLabel];
// after
answer.selected_values = [question.options.find((o) => o.label === selectedLabel)!.value];
Defensive patterns

Strategy: validation

Validate before calling

const known = new Set(question.options.map((o) => o.value));
if (answer.kind === 'option' && !known.has(answer.selected_values[0]!)) throw new Error('value not in schema — remap from fresh schema');

Type guard

function valueInSchema(q: NormalizedQuestionItem, v: string): boolean { return q.options.some((o) => o.value === v); }

Try / catch

try { await submit(p, answers); } catch (e) { if ((e as Error & { code?: string }).code === 'question_invalid_answer' && /not in the option schema/.test((e as Error).message)) { await remapValuesFromFreshSchema(); return submit(p, answers); } throw e; }

Prevention

When it happens

Trigger: kind 'option' where selected_values[0] is not in optionValues — e.g. a label, a sentinel, or a value from an outdated schema.

Common situations: Submitting labels instead of values; stale client schema after options changed; hand-crafted payloads in scripts/tests with guessed values.

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


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/21e09fe0d7a4b869. Report an issue: GitHub.