{"record":{"id":"db9b69c53dab763a","repo":"can1357/oh-my-pi","slug":"context-systemprompt-must-be-an-array-of-strings","errorCode":null,"errorMessage":"`context.systemPrompt` must be an array of strings when present","messagePattern":"`context\\.systemPrompt` must be an array of strings when present","errorType":"validation","errorClass":"AIError.ValidationError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/providers/pi-native-server.ts","lineNumber":128,"sourceCode":"\t\tmodelId = obj.modelId;\n\t} else if (typeof obj.model === \"string\" && obj.model.length > 0) {\n\t\tmodelId = obj.model;\n\t} else if (typeof obj.model === \"object\" && obj.model !== null) {\n\t\tconst m = obj.model as Record<string, unknown>;\n\t\tif (typeof m.id === \"string\" && m.id.length > 0) modelId = m.id;\n\t}\n\tif (!modelId) throw new AIError.ValidationError(\"Missing `modelId` (or `model.id`) field\");\n\n\tconst context = obj.context;\n\tif (typeof context !== \"object\" || context === null || Array.isArray(context)) {\n\t\tthrow new AIError.ValidationError(\"Missing `context` object\");\n\t}\n\tconst ctxObj = context as Record<string, unknown>;\n\tif (!Array.isArray(ctxObj.messages)) {\n\t\tthrow new AIError.ValidationError(\"`context.messages` must be an array\");\n\t}\n\tif (ctxObj.systemPrompt !== undefined && !Array.isArray(ctxObj.systemPrompt)) {\n\t\tthrow new AIError.ValidationError(\"`context.systemPrompt` must be an array of strings when present\");\n\t}\n\tif (ctxObj.tools !== undefined && !Array.isArray(ctxObj.tools)) {\n\t\tthrow new AIError.ValidationError(\"`context.tools` must be an array when present\");\n\t}\n\n\tconst options: SimpleStreamOptions = {};\n\tconst rawOpts = obj.options;\n\tif (typeof rawOpts === \"object\" && rawOpts !== null && !Array.isArray(rawOpts)) {\n\t\tconst optsBag = options as Record<string, unknown>;\n\t\tfor (const [k, v] of Object.entries(rawOpts)) {\n\t\t\tif (v === undefined || v === null) continue;\n\t\t\tif (!ALLOWED_OPTION_KEYS.has(k as keyof SimpleStreamOptions)) continue;\n\t\t\toptsBag[k] = v;\n\t\t}\n\t}\n\n\t// `stream` defaults to true — pi-native clients overwhelmingly stream, and\n\t// matching `streamProxy`'s implicit-stream behavior avoids a one-flag papercut.","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/ai/src/providers/pi-native-server.ts#L110-L146","documentation":"parseRequest treats `context.systemPrompt` as optional, but when present it must be an array (of strings, per the message). Passing a bare string or any other non-array type raises this ValidationError so the server never receives a malformed system prompt.","triggerScenarios":"Sending `context:{\"systemPrompt\":\"You are helpful\",...}` — a string instead of an array of strings.","commonSituations":"OpenAI-style clients used to `system` role strings; copying examples where systemPrompt was a single string; concatenating multiple prompt blocks into one string instead of array entries.","solutions":["Wrap the system prompt in an array, e.g. `\"systemPrompt\":[\"You are helpful\"]`","For multiple prompt blocks, pass each block as a separate array element","Omit the field entirely if no system prompt is needed"],"exampleFix":"// before\n{\"context\":{\"messages\":[...],\"systemPrompt\":\"You are helpful\"}}\n// after\n{\"context\":{\"messages\":[...],\"systemPrompt\":[\"You are helpful\"]}}","handlingStrategy":"validation","validationCode":"const sp = body?.context?.systemPrompt;\nif (sp !== undefined && !(Array.isArray(sp) && sp.every(s => typeof s === 'string'))) throw new Error('context.systemPrompt must be string[] when present');","typeGuard":"function hasStringArraySystemPrompt(ctx: { systemPrompt?: unknown }): ctx is { systemPrompt?: string[] } {\n  return ctx.systemPrompt === undefined || (Array.isArray(ctx.systemPrompt) && ctx.systemPrompt.every(s => typeof s === 'string'));\n}","tryCatchPattern":"try { const req = parseRequest(body); } catch (e) { if (e instanceof AIError.ValidationError && String(e.message).includes('systemPrompt')) return respond400('context.systemPrompt must be an array of strings'); throw e; }","preventionTips":["Represent system prompts as string[] end-to-end","Normalize string prompts to [prompt] at load time","Cover systemPrompt shape in payload tests"],"tags":["validation","request-schema","system-prompt"],"backgroundTag":"schema-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}