Skip to content

fix(llm): use validated messages variable instead of raw params access#5165

Open
Ricardo-M-L wants to merge 1 commit intocrewAIInc:mainfrom
Ricardo-M-L:fix/use-validated-messages-variable
Open

fix(llm): use validated messages variable instead of raw params access#5165
Ricardo-M-L wants to merge 1 commit intocrewAIInc:mainfrom
Ricardo-M-L:fix/use-validated-messages-variable

Conversation

@Ricardo-M-L
Copy link
Copy Markdown

@Ricardo-M-L Ricardo-M-L commented Mar 30, 2026

Fixes #5164

Both _handle_non_streaming_response and _ahandle_non_streaming_response extract and validate messages with params.get("messages", []), but then pass params["messages"] to _handle_emit_call_events. This would raise a confusing KeyError instead of the intended ValueError if the key is missing.

Changed params["messages"] to messages on both lines (sync and async).


Note

Low Risk
Low risk: a small bug fix that only changes which messages value is passed into LLM call-completed events, avoiding KeyError when params lacks messages.

Overview
Fixes non-streaming LLM event emission for response_model calls (sync and async) by passing the already-extracted/validated messages variable into _handle_emit_call_events instead of directly indexing params["messages"].

This prevents a confusing KeyError when messages are missing and preserves the intended validation error behavior.

Reviewed by Cursor Bugbot for commit ca46bf5. Bugbot is set up for automated code reviews on this repo. Configure here.

Both _handle_non_streaming_response and its async variant extract
messages via params.get("messages", []) and validate them, but then
pass params["messages"] to _handle_emit_call_events. If the key is
missing this raises a confusing KeyError instead of the intended
ValueError. Use the already-validated `messages` variable instead.

Signed-off-by: Ricardo-M-L <ricardoporsche001@icloud.com>
@Ricardo-M-L Ricardo-M-L force-pushed the fix/use-validated-messages-variable branch from 3547be4 to ca46bf5 Compare April 18, 2026 17:19
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.

[BUG] KeyError when params missing 'messages' key in _handle_non_streaming_response

1 participant