Skip to content

fix(bedrock): return no output instead of throwing when a Nova message has no content - #11812

Merged
mldangelo-oai merged 3 commits into
promptfoo:mainfrom
kabishou11:fix/bedrock-nova-missing-content
Nov 5, 2026
Merged

mldangelo-oai merged 3 commits into
promptfoo:mainfrom
kabishou11:fix/bedrock-nova-missing-content

Conversation

@kabishou11

Copy link
Copy Markdown
Contributor

novaOutputFromMessage in src/providers/bedrock/util.ts reads response.output?.message?.content.some(...). The optional chain stops before .some, so a Nova response whose message has no content array throws instead of producing an empty output:

novaOutputFromMessage({ output: { message: { role: 'assistant' } } });
// TypeError: Cannot read properties of undefined (reading 'some')

You don't need a malformed response to reach this. The Nova 2 handler in src/providers/bedrock/index.ts sends exactly this shape here: when content is missing or not an array, it calls novaOutputFromMessage(responseJson). The Converse parser already treats missing content as empty (outputMessage?.content || []).

The fix extends the optional chain to content?.some / content?.map, so missing content returns undefined, the same result as an empty response. Responses that have content are unchanged.

Test: should handle message without content without throwing in test/providers/bedrock/util.test.ts fails on main with the TypeError and passes with the fix. The file passes (8 tests), and Biome is clean.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-16T13:36:30.904682Z b7a1762 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.33%. Comparing base (69f84c3) to head (5b7c7ca).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11812      +/-   ##
==========================================
- Coverage   89.33%   89.33%   -0.01%     
==========================================
  Files        1030     1030              
  Lines       93013    93013              
  Branches    32882    32882              
==========================================
- Hits        83093    83090       -3     
- Misses       9920     9923       +3     
Flag Coverage Δ
backend 90.07% <100.00%> (-0.01%) ⬇️
site 51.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@promptfoo-scanner promptfoo-scanner Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 All Clear

Reviewed changes to Bedrock Nova response handling and associated tests. The PR makes message content optional and returns undefined instead of throwing when absent. Based on the diff, there are no new LLM-related security risks introduced.

Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more


Was this helpful?  👍 Yes  |  👎 No 

@kimnamu

kimnamu commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Thanks @kabishou11 for tracing this through the Nova 2 handler. The !content || !Array.isArray(content) branch handing the response straight to novaOutputFromMessage is easy to miss, and your test pins it down.

I ran novaOutputFromMessage as it exists in src/providers/bedrock/util.ts at main 5ed7767 and at this PR's head 6330857, against your shape and against raw InvokeModel responses from Bedrock (us-east-1). The PR removes the crash. The real Nova 1 responses give identical output on both, and the Nova 2 ones never reach the changed lines.

Input main 5ed7767 PR 6330857
{ output: { message: { role: 'assistant' } } } ❌ TypeError at util.ts:94 ✅ undefined
Nova Micro v1 reply (end_turn, one text block) "Hello there!" ✅ same
Nova Lite v1 tool call (tool_use, text + toolUse blocks) toolUse JSON ✅ same
Nova 2 Lite cut off by max_new_tokens (reasoning on and off) content is still an array, so index.ts:1471 never calls novaOutputFromMessage ✅ not affected
PR shape: message without content | stop=- | blocks=[]
  main: TypeError: Cannot read properties of undefined (reading 'some')
  PR  : undefined
live nova1-text | stop=end_turn | blocks=["text"]
  main: "Hello there!"
  PR  : "Hello there!"
live nova1-tool | stop=tool_use | blocks=["text","toolUse"]
  main: "{\"name\":\"get_weather\",\"toolUseId\":\"…\",\"input\":{\"city\":\"Paris\"}}"
  PR  : "{\"name\":\"get_weather\",\"toolUseId\":\"…\",\"input\":{\"city\":\"Paris\"}}"
How I checked
  • AmazonResponse and novaOutputFromMessage were copied verbatim from util.ts at each sha and run under Node 22 type stripping. The function uses nothing else from the module. I did not run the vitest suite.
  • Live calls were InvokeModel with schemaVersion: "messages-v1" on us.amazon.nova-micro-v1:0, us.amazon.nova-lite-v1:0 (one-tool toolConfig) and us.amazon.nova-2-lite-v1:0.
  • Nova 2 Lite returned stopReason: "max_tokens" with a one-block content array in all three tries: reasoningContent only (reasoning low, max_new_tokens 1 and 16) and a text block (no reasoningConfig, max_new_tokens 1). None of the requests I tried returned a message with no content key.

@kabishou11

Copy link
Copy Markdown
Contributor Author

Thanks for the live Bedrock check — glad the Nova 1 paths stay identical and the crash is gone.

@mldangelo-oai
mldangelo-oai merged commit 8fd968a into promptfoo:main Nov 5, 2026
109 of 110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants