{"record":{"id":"9a46001c1f3c2291","repo":"n8n-io/n8n","slug":"additional-model-request-fields-must-be-valid-json-9a4600","errorCode":null,"errorMessage":"Additional Model Request Fields must be valid JSON","messagePattern":"Additional Model Request Fields must be valid JSON","errorType":"validation","errorClass":"UserError","httpStatus":null,"severity":"warning","filePath":"packages/@n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts","lineNumber":432,"sourceCode":"\t\tconst guardrail = options.guardrail?.values;\n\t\tif (guardrail?.guardrailIdentifier) {\n\t\t\tmodelConfig.guardrailConfig = {\n\t\t\t\tguardrailIdentifier: guardrail.guardrailIdentifier,\n\t\t\t\t// AWS requires a version whenever guardrailConfig is sent. The field may be blank,\n\t\t\t\t// whitespace (e.g. from an expression), or absent (collection defaults only\n\t\t\t\t// materialize on add); fall back to the working draft.\n\t\t\t\tguardrailVersion: guardrail.guardrailVersion?.trim() || 'DRAFT',\n\t\t\t\t...(guardrail.trace ? { trace: guardrail.trace } : {}),\n\t\t\t};\n\t\t}\n\n\t\tconst additionalFields = options.additionalModelRequestFields?.trim();\n\t\tif (additionalFields && additionalFields !== '{}') {\n\t\t\tlet parsed: DocumentType;\n\t\t\ttry {\n\t\t\t\tparsed = jsonParse<DocumentType>(additionalFields);\n\t\t\t} catch {\n\t\t\t\tthrow new UserError('Additional Model Request Fields must be valid JSON', {\n\t\t\t\t\tlevel: 'warning',\n\t\t\t\t});\n\t\t\t}\n\t\t\tmodelConfig.additionalModelRequestFields = parsed;\n\t\t}\n\n\t\tconst model = new ChatBedrockConverse(modelConfig);\n\n\t\treturn {\n\t\t\tresponse: model,\n\t\t};\n\t}\n}\n","sourceCodeStart":414,"sourceCodeEnd":446,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.ts#L414-L446","documentation":"Identical in spirit to error 682 but in the Bedrock Chat node: options.additionalModelRequestFields is a free-text JSON string; if it is non-empty, non-'{}', and fails jsonParse, a UserError (warning level) is thrown. Bedrock's Converse API accepts arbitrary model request overrides as a JSON object.","triggerScenarios":"User enters malformed JSON in 'Additional Model Request Fields' on the Bedrock Chat node — unquoted keys, trailing commas, smart quotes, or a templated expression resolving to invalid JSON.","commonSituations":"Pasting from Bedrock docs with single quotes; expression returning undefined; hand-editing; copy-paste with mangled characters.","solutions":["Open 'Additional Model Request Fields' and paste valid JSON, e.g. {\"inferenceConfig\": {\"maxTokens\": 512}}.","Run the string through a JSON linter.","If templated, ensure the expression returns a valid JSON string or use {} / leave empty.","Consult the Bedrock Converse API docs for the exact key names allowed."],"exampleFix":"// before\noptions.additionalModelRequestFields = \"inferenceConfig: {maxTokens: 512}\"\n// after\noptions.additionalModelRequestFields = \"{\\\"inferenceConfig\\\": {\\\"maxTokens\\\": 512}}\"","handlingStrategy":"validation","validationCode":"const raw = options.additionalModelRequestFields?.trim();\nif (raw && raw !== '{}') {\n  try { JSON.parse(raw); }\n  catch (e) { throw new Error(`Fix JSON: ${(e as Error).message}`); }\n}","typeGuard":"const isJsonString = (s: string): boolean => { try { JSON.parse(s); return true; } catch { return false; } };","tryCatchPattern":"// Pre-validate at save; runtime catch only rewraps.","preventionTips":["Validate the JSON field in the UI as the user types.","Use {} or leave empty when no overrides are needed.","Mirror the Bedrock Converse API key names in any examples."],"tags":["bedrock","llm","json","configuration","user-input"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}