{"record":{"id":"81fb32f708bbb647","repo":"DayuanJiang/next-ai-draw-io","slug":"google-top-p-must-be-a-number-between-0-and-1-got","errorCode":null,"errorMessage":"GOOGLE_TOP_P must be a number between 0 and 1, got: ${process.env.GOOGLE_TOP_P}","messagePattern":"GOOGLE_TOP_P must be a number between 0 and 1, got: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/ai-providers.ts","lineNumber":405,"sourceCode":"                1,\n                8,\n            )\n            if (candidateCount) {\n                options_obj.candidateCount = candidateCount\n            }\n            const topK = parseIntSafe(\n                process.env.GOOGLE_TOP_K,\n                \"GOOGLE_TOP_K\",\n                1,\n                100,\n            )\n            if (topK) {\n                options_obj.topK = topK\n            }\n            if (process.env.GOOGLE_TOP_P) {\n                const topP = Number.parseFloat(process.env.GOOGLE_TOP_P)\n                if (Number.isNaN(topP) || topP < 0 || topP > 1) {\n                    throw new Error(\n                        `GOOGLE_TOP_P must be a number between 0 and 1, got: ${process.env.GOOGLE_TOP_P}`,\n                    )\n                }\n                options_obj.topP = topP\n            }\n\n            if (Object.keys(options_obj).length > 0) {\n                options.google = { ...options.google, ...options_obj }\n            }\n            break\n        }\n        case \"vertexai\": {\n            const thinkingBudget = parseIntSafe(\n                process.env.GOOGLE_VERTEX_THINKING_BUDGET,\n                \"GOOGLE_VERTEX_THINKING_BUDGET\",\n                1024,\n                100000,\n            )","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/DayuanJiang/next-ai-draw-io/blob/155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1/lib/ai-providers.ts#L387-L423","documentation":"buildProviderOptions parses GOOGLE_TOP_P as a float and requires it in [0,1]; NaN, negative, or >1 values throw with the offending raw string.","triggerScenarios":"GOOGLE_TOP_P=100 (percent-style), '0,5' (comma decimal), or any non-numeric string in .env.local.","commonSituations":"Developers entering a percentage (50 instead of 0.5), locale-formatted decimals, or trailing characters.","solutions":["Use a decimal between 0 and 1 (e.g. GOOGLE_TOP_P=0.9)","Use a dot as decimal separator","Remove the variable to use the provider default"],"exampleFix":"# before\nGOOGLE_TOP_P=90\n\n# after\nGOOGLE_TOP_P=0.9","handlingStrategy":"validation","validationCode":"const topP = Number.parseFloat(process.env.GOOGLE_TOP_P ?? '')\nconst ok = Number.isNaN(topP) ? !process.env.GOOGLE_TOP_P : (topP >= 0 && topP <= 1)","typeGuard":"const isValidTopP = (v: string): boolean => { const n = Number.parseFloat(v); return !Number.isNaN(n) && n >= 0 && n <= 1 }","tryCatchPattern":"try { ... } catch (e) { if ((e as Error).message.includes('GOOGLE_TOP_P')) fixTopPEnv() }","preventionTips":["Express top_p as a 0–1 fraction, never a percentage","Use dot decimals, not commas"],"tags":["env-var","validation","google","range"],"backgroundTag":"invalid-env-var-value","analyzedSha":"155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1","analyzedAt":"2026-08-27T11:40:38.297Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}