{"record":{"id":"e05a537acb83bcea","repo":"amruthpillai/reactive-resume","slug":"the-model-returned-too-much-text-during-the-provid","errorCode":null,"errorMessage":"The model returned too much text during the provider test.","messagePattern":"The model returned too much text during the provider test\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/api/src/features/ai/service.ts","lineNumber":158,"sourceCode":"export const fileInputSchema = z.object({\n\tname: z.string(),\n\tdata: z.string().max(MAX_AI_FILE_BASE64_CHARS, \"File is too large. Maximum size is 10MB.\"),\n});\n\ntype TestConnectionInput = z.infer<typeof aiCredentialsSchema>;\n\nexport async function testConnection(input: TestConnectionInput): Promise<boolean> {\n\tconst RESPONSE_OK = \"1\";\n\n\tconst result = await generateText({\n\t\tmodel: getModel(input),\n\t\tmaxOutputTokens: TEST_CONNECTION_MAX_OUTPUT_TOKENS,\n\t\ttemperature: 0,\n\t\tmessages: [{ role: \"user\", content: `Respond only with the single character: ${RESPONSE_OK}` }],\n\t});\n\n\tif (result.text.trim() === RESPONSE_OK) return true;\n\tif (result.finishReason === \"length\") throw new Error(\"The model returned too much text during the provider test.\");\n\n\treturn false;\n}\n\ntype ParsePdfInput = z.infer<typeof aiCredentialsSchema> & {\n\tfile: z.infer<typeof fileInputSchema>;\n};\n\ntype BuildResumeParsingMessagesInput = {\n\tuserPrompt: string;\n\tfile: z.infer<typeof fileInputSchema>;\n\tmediaType: string;\n};\n\nfunction buildResumeParsingSystemPrompt(systemPrompt: string): string {\n\treturn `${systemPrompt}\\n\\nIMPORTANT: You must return ONLY raw valid JSON. Do not return markdown, do not return explanations. Just the JSON object. Use the following JSON as a template and fill in the extracted values. For arrays, you MUST use the exact key names shown in the template (e.g. use 'description' instead of 'summary', 'website' instead of 'url'):\\n\\n${JSON.stringify(aiExtractionTemplate, null, 2)}`;\n}\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/amruthpillai/reactive-resume/blob/3a5b12e2a40374a9571988701fcb75c5a1831c42/packages/api/src/features/ai/service.ts#L140-L176","documentation":"Plain Error (not an ORPCError) thrown by testConnection when the model's finishReason is 'length' during the provider connectivity test. The test asks the model to respond with a single character; if it hit the maxOutputTokens cap (TEST_CONNECTION_MAX_OUTPUT_TOKENS) before completing, the model is considered misbehaving (verbose/looping) and the test fails with this message. Because it is a plain Error, callers that do not remap it will see it bubble up; the ai-providers test handler remaps it to BAD_GATEWAY 'Could not reach the AI provider.'.","triggerScenarios":"POST /ai-providers/{id}/test (or a direct testConnection call) where the model ignores the 'respond with 1' instruction and emits text until the token cap, setting finishReason='length'. Common with poorly-instructed local models or models that prepend long preambles.","commonSituations":"Self-hosted/Ollama model that does not follow short-response instructions; a model that outputs chain-of-thought despite temperature 0; an overly small maxOutputTokens constant; a misconfigured gateway that injects verbose logging into the response.","solutions":["Use a model that follows concise-response instructions; instruct-tuned chat models behave best.","If self-hosting, raise TEST_CONNECTION_MAX_OUTPUT_TOKENS or tune the model's system prompt to be terse.","Confirm the baseURL points to the chat/completions endpoint and not a verbose logging surface.","Switch to a better-quantized or larger model variant that respects output constraints."],"exampleFix":"// before\n// local model loops, hits token cap\nmodel: 'ollama:llama2-uncensored'\n\n// after\nmodel: 'ollama:llama3.1-instruct' // follows 'respond with 1' instruction","handlingStrategy":"retry","validationCode":"async function probeModelTerse(input) {\n  const r = await generateText({ model: getModel(input), maxOutputTokens: 16, temperature: 0, messages: [{ role: 'user', content: 'Respond only with: 1' }] });\n  return r.finishReason !== 'length';\n}","typeGuard":"function isLengthFinish(error) {\n  return error instanceof Error && /too much text during the provider test/i.test(error.message);\n}","tryCatchPattern":"try {\n  await testProvider({ id });\n} catch (e) {\n  if (e?.code === 'BAD_GATEWAY' || /too much text during the provider test/i.test(e.message)) {\n    showToast('The model is too verbose for the connectivity test; try a different model.');\n  } else throw e;\n}","preventionTips":["Prefer instruct-tuned models that obey concise-response instructions.","For self-hosted models, raise the test token cap or tune the system prompt.","Do not use models known to emit long preambles for the provider test."],"tags":["ai","test","model-behavior","token-limit","config"],"backgroundTag":null,"analyzedSha":"3a5b12e2a40374a9571988701fcb75c5a1831c42","analyzedAt":"2026-08-12T22:31:22.666Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}