Skip to content

Conversation

@j3r0lin
Copy link

@j3r0lin j3r0lin commented Dec 4, 2025

Fix KeyError when processing assistant message content blocks in _construct_responses_api_input function. The code was directly accessing block["text"] without checking if the key exists, which could cause a KeyError when processing malformed or incomplete content blocks.

This change adds defensive checks using block.get("text") to safely handle cases where the "text" key might be missing from content blocks with type "text" or "output_text".

cursoragent and others added 2 commits December 4, 2025 01:48
Add defensive check for missing 'text' key in text/output_text blocks
when constructing Responses API input. Blocks without 'text' key are
now skipped instead of raising KeyError.

- Add defensive check using block.get('text') for text/output_text blocks
- Skip blocks when text is None
- Add test case to verify blocks without text key are skipped

Fixes issue where block_type is 'text' or 'output_text' but block
dictionary lacks 'text' key, causing KeyError.
…ponses-api-composer-1-c756

Fix missing text key in responses api
@j3r0lin j3r0lin requested review from ccurme and mdrxy as code owners December 4, 2025 01:53
@github-actions github-actions bot added integration Related to a provider partner package integration openai fix labels Dec 4, 2025
@mdrxy
Copy link
Member

mdrxy commented Dec 4, 2025

Why would this ever be the case? What usage prompted this?

@j3r0lin
Copy link
Author

j3r0lin commented Dec 4, 2025

I found that when using the GPT-5.1 model, occasionally the first chunk of its response is [{ "type": "text", index: -1 }], but this happens very rarely.

CleanShot 2025-12-04 at 10 22 20@2x

@mdrxy
Copy link
Member

mdrxy commented Dec 4, 2025

Is this using the OpenAI API directly or wrapping via some proxy/router service?

@j3r0lin
Copy link
Author

j3r0lin commented Dec 4, 2025

OpenAI API directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix integration Related to a provider partner package integration openai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants