Skip to content

fix(llm): use validated messages variable in non-streaming handlers#5655

Merged
greysonlalonde merged 2 commits intomainfrom
gl/fix/llm-validated-messages
Apr 29, 2026
Merged

fix(llm): use validated messages variable in non-streaming handlers#5655
greysonlalonde merged 2 commits intomainfrom
gl/fix/llm-validated-messages

Conversation

@greysonlalonde
Copy link
Copy Markdown
Contributor

@greysonlalonde greysonlalonde commented Apr 29, 2026

Summary

  • In _handle_non_streaming_response and _ahandle_non_streaming_response, the response_model + litellm path validates messages via params.get("messages", []) and raises a clear ValueError if missing, but then re-indexes params["messages"] a few lines later when calling _handle_emit_call_events — which would raise a confusing KeyError instead.
  • Use the already-validated local messages variable in both call sites.

Note

Low Risk
Small, localized change to event payload wiring in the non-streaming response_model path; no changes to completion behavior or data processing.

Overview
Fixes event emission in _handle_non_streaming_response and _ahandle_non_streaming_response when response_model is used with the LiteLLM path.

Instead of re-indexing params["messages"] (which could raise a KeyError despite earlier validation), the code now passes the already-validated local messages variable into _handle_emit_call_events, preserving the intended ValueError for missing messages.

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

Copy link
Copy Markdown
Contributor

@iris-clawd iris-clawd left a comment

Choose a reason for hiding this comment

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

LGTM — uses the already-validated local messages variable instead of re-indexing params. Clean fix.

@greysonlalonde greysonlalonde merged commit 2a40316 into main Apr 29, 2026
54 checks passed
@greysonlalonde greysonlalonde deleted the gl/fix/llm-validated-messages branch April 29, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants