Skip to content

fix(models): populate model_version on AnthropicLlm responses - #6850

Open
omar-infinitusai wants to merge 2 commits into
google:mainfrom
omar-infinitusai:feat-anthropic-integration-model_version
Open

fix(models): populate model_version on AnthropicLlm responses#6850
omar-infinitusai wants to merge 2 commits into
google:mainfrom
omar-infinitusai:feat-anthropic-integration-model_version

Conversation

@omar-infinitusai

@omar-infinitusai omar-infinitusai commented Aug 21, 2026

Copy link
Copy Markdown

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
AnthropicLlm never sets LlmResponse.model_version. The Anthropic API
returns the resolved model snapshot on every response (Message.model), but
neither the non-streaming nor the streaming path reads it. Every other model
wrapper (google_llm.py, lite_llm.py, apigee_llm.py) already populates
this field.

Solution:
Set model_version=message.model in message_to_generate_content_response(),
and thread event.message.model through the streaming path to every yielded
LlmResponse, partials included, matching lite_llm.py's parity there.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added two tests that assert on model_version directly (not just mock
plumbing): one for the non-streaming response, one covering both a partial
and the final streaming response.

$ pytest tests/unittests/models/test_anthropic_llm.py -q
138 passed

Manual End-to-End (E2E) Tests:

Run against the live Anthropic API by building and running package locally in an existing application.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

message_to_generate_content_response() and the streaming message_start
handler never read the Anthropic Message.model field, so every
LlmResponse AnthropicLlm produced had model_version=None. Other
first-party model wrappers (google_llm, lite_llm, apigee_llm) already
set this from their respective API responses; AnthropicLlm was the
one path where it stayed null, which meant DatabaseSessionService-
persisted events and the gen_ai.response.model telemetry attribute
had no way to tell which resolved Claude snapshot served a turn.

Set model_version=message.model in the non-streaming path. On the
streaming path, thread event.message.model through to every yielded
LlmResponse, partials included, matching lite_llm.py's parity between
partial and final responses.

Add real assertions on model_version for both paths (non-streaming and
streaming, partial and final), not just the mock plumbing needed to
give MagicMock.model a string value.

Fixes google#6847
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.

AnthropicLlm never populates LlmResponse.model_version

2 participants