linshenkx/prompt-optimizer · error · VariableError

VALUE_TOO_LONG

VALUE_TOO_LONG

Error message

Variable value too long: ${value.length} > ${VARIABLE_VALIDATION.MAX_VALUE_LENGTH}

What it means

VariableManager.setVariable throws VariableError with code VALUE_TOO_LONG when the value string exceeds VARIABLE_VALIDATION.MAX_VALUE_LENGTH. This is a guard against unbounded storage growth (values are persisted via saveToStorage, e.g. to localStorage). The error message reports both the actual length and the limit.

Source

Thrown at packages/ui/src/services/VariableManager.ts:130

      throw new VariableError(
        `Invalid variable name: ${name}. ${reasonText}`,
        name,
        undefined,
        'INVALID_VARIABLE_NAME'
      );
    }

    if (this.isPredefinedVariable(name)) {
      throw new VariableError(
        `Cannot override predefined variable: ${name}`,
        name,
        undefined,
        'PREDEFINED_VARIABLE_OVERRIDE'
      );
    }

    if (value.length > VARIABLE_VALIDATION.MAX_VALUE_LENGTH) {
      throw new VariableError(
        `Variable value too long: ${value.length} > ${VARIABLE_VALIDATION.MAX_VALUE_LENGTH}`,
        name,
        undefined,
        'VALUE_TOO_LONG'
      );
    }

    this.customVariables[name] = value;
    this.saveToStorage();
  }

  getVariable(name: string): string | undefined {
    return this.customVariables[name];
  }

  deleteVariable(name: string): void {
    if (this.isPredefinedVariable(name)) {
      throw new VariableError(

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Truncate or reject long values client-side before calling setVariable
  2. Store large payloads out-of-band (e.g. an asset/image storage service) and keep only a reference ID in the variable
  3. Check VARIABLE_VALIDATION.MAX_VALUE_LENGTH and surface a form validation message instead of relying on the throw

Example fix

// before
variableManager.setVariable('doc', hugeString)

// after
if (hugeString.length > VARIABLE_VALIDATION.MAX_VALUE_LENGTH) {
  throw new Error(`Value exceeds ${VARIABLE_VALIDATION.MAX_VALUE_LENGTH} chars`)
}
variableManager.setVariable('doc', hugeString)
Defensive patterns

Strategy: validation

Validate before calling

const MAX = VARIABLE_VALIDATION.MAX_VALUE_LENGTH
if (value.length > MAX) {
  throw new RangeError(`Value too long: ${value.length} > ${MAX}`)
}

Type guard

const fitsVariableLimit = (value: string): boolean =>
  value.length <= VARIABLE_VALIDATION.MAX_VALUE_LENGTH

Try / catch

try {
  vm.setVariable(name, value)
} catch (e) {
  if (e instanceof VariableError && e.code === 'VALUE_TOO_LONG') {
    value = value.slice(0, VARIABLE_VALIDATION.MAX_VALUE_LENGTH)
    vm.setVariable(name, value)
  } else throw e
}

Prevention

When it happens

Trigger: Calling setVariable(name, value) with value.length > VARIABLE_VALIDATION.MAX_VALUE_LENGTH. Typical with base64-encoded images, large JSON blobs, or pasted text stored as a variable.

Common situations: Storing base64 image data or long documents in a variable; importing variables from a file created under different limits; localStorage quota issues that surface as oversized payloads.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/6a8aee93f0f3dc13. Report an issue: GitHub.