Skip to main content

Validation field codes

Console request 2026-11-20 §3, added 2026-11-23. Every VALIDATION_FAILED error (422 for bodies, 400 for query strings) carries machine-readable reasons next to the human-readable messages. Clients switch on the codes. The messages are for people and may change.

{
error: {
code: "VALIDATION_FAILED",
message: string,
details: {
fieldErrors?: { [field: string]: string[] }, // unchanged: human-readable
formErrors?: string[], // unchanged
fieldCodes: { [field: string]: string[] }, // NEW, always present: same keys and order as fieldErrors
formCodes?: string[], // NEW, present when formErrors is: same order
// …every other key a route already returned (field, reason, cause, unknown, allowed, …) is unchanged
},
requestId: string
}
}

Rules​

  • The change is additive. No existing key changed or moved; clients that ignore fieldCodes see no difference.
  • fieldCodes[f][i] is the reason for fieldErrors[f][i]. The arrays have the same length.
  • A field is the top-level body or query key (Zod's path[0]). Domain checks may use a dotted name such as batteryTemperature.enabled or period.from, exactly as in fieldErrors.
  • A domain error shaped {field, reason} (no fieldErrors) gets fieldCodes: { [field]: [reason] } when reason is UPPER_SNAKE, otherwise INVALID.
  • Unknown query parameters on a strict route (details.unknown) get UNKNOWN_FIELD each.
  • Codes are stable: never renamed or removed once shipped. New codes may be added, so treat an unknown code like INVALID.
  • Source of truth: VALIDATION_FIELD_CODES in cse-http-be packages/core/src/validation-codes.ts. The pipeline adds the codes in packages/api/src/http/respond.ts.

Generic codes (schema checks)​

CodeMeaning
REQUIREDthe field is missing (or required by another field's value)
INVALID_TYPEwrong JSON type (e.g. a number where a string is expected)
INVALID_NUMBERnot a finite number
INVALID_VALUEnot one of the allowed literal/union values
INVALID_ENUMnot one of the listed enum values
INVALID_FORMATstring does not match the expected format (ULID, regex, …)
INVALID_EMAILnot an email address
INVALID_URLnot a URL
INVALID_DATETIMEnot an ISO-8601 date/time
INVALID_DATEnot a valid date
NOT_MULTIPLE_OFnumber is not a multiple of the step
TOO_SHORT / TOO_LONG / INVALID_LENGTHstring length below minimum / above maximum / not the exact length
TOO_SMALL / TOO_LARGEnumber or date out of range
TOO_FEW_ITEMS / TOO_MANY_ITEMSarray size out of range
UNKNOWN_FIELDthe field is not accepted (strict body or query)
BODY_NOT_ALLOWEDthe route takes no body (form-level)
INVALIDany other failure, including a custom rule with no specific code yet

Domain codes​

CodeField(s) todayMeaning
INCOMPATIBLE_WITH_GRID_CONNECTIONexportRate (plant tariff)only allowed on grid-connected plants
REQUIRES_BATTERYbatteryTemperature.enabled (plant alert rules)the plant has no battery
MUST_DIFFERnotifications.quietHours.endstart and end must differ
NOT_ACCEPTEDphonethe identity provider refused the value
NOT_ALLOWED_FOR_ROLEbusinessOrgId (plant transfer)only Super Admin / Administrator may set it
REQUIRES_CUSTOMERinviteCustomer (create plant)needs a customer
CUSTOMER_EMAIL_MISSINGinviteCustomerthe customer has no contact email
TEMPLATE_UNAVAILABLEtemplateKey (reports)not an available template
REQUIRES_CUSTOMER_TEMPLATEperCustomer (report schedules)needs a CUSTOMER-audience template
RECIPIENTS_WITHOUT_ACCESSrecipients (report schedules)some recipients cannot see reports on this scope
OUT_OF_RANGElimit (report schedules list)integer outside the allowed range
PLATFORM_ORG_NOT_ALLOWEDX-Org-Id (reports)select a Business, not the platform org
MULTIPLE_OPERATORSscope.ids (reports)plants span more than one operator
INVALID_TIMEZONEtimezonenot an IANA time zone
RANGE_INVERTEDperiod.fromstart after end
IN_FUTUREperiod.toends in the future
RANGE_TOO_LONGperiodspans more days than allowed
NOT_FOUND_IN_ORGscope, recipients (notification rules)a referenced target does not exist in the organisation

Reasons passed through from {field, reason} errors​

These routes already returned details.reason; it now also appears as the field's code:

INELIGIBLE_ASSIGNEE (work-order technician, alert installer proof), DEVICE_NOT_ON_PLANT, CUSTOMER_NOT_LINKED, CUSTOMER_PLANT_MISMATCH, END_USER_ONLY, END_USER_SCOPE_PLANTS_ONLY, INSTALLER_SCOPE_PLANTS_ONLY, SCOPE_RULE_FORCES_ALL, CONFIRMATION_REQUIRED, ASSET_NOT_FOUND, ASSET_NOT_READY, ASSET_SLOT_MISMATCH, NOT_AN_IMAGE, SIZE_MISMATCH, TYPE_MISMATCH. A {field} error with no reason gets INVALID.

Illustrative example (not a captured execution)​

Derived from assertTariffFitsPlant (packages/core/src/plants/settings.ts): setting an export rate on an off-grid plant.

{
"error": {
"code": "VALIDATION_FAILED",
"message": "Request validation failed",
"details": {
"formErrors": [],
"fieldErrors": { "exportRate": ["is only allowed on grid-connected plants"] },
"fieldCodes": { "exportRate": ["INCOMPATIBLE_WITH_GRID_CONNECTION"] },
"formCodes": []
},
"requestId": "<request id>"
}
}