Skip to content

Fix Bedrock Anthropic adapter by adding required anthropic_version field#17744

Merged
harupy merged 4 commits intomlflow:masterfrom
harupy:fix-bedrock-anthropic-version
Nov 15, 2025
Merged

Fix Bedrock Anthropic adapter by adding required anthropic_version field#17744
harupy merged 4 commits intomlflow:masterfrom
harupy:fix-bedrock-anthropic-version

Conversation

@harupy
Copy link
Member

@harupy harupy commented Sep 16, 2025

🛠 DevTools 🛠

Open in GitHub Codespaces

Install mlflow from this PR

# mlflow
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/17744/merge
# mlflow-skinny
pip install git+https://github.com/mlflow/mlflow.git@refs/pull/17744/merge#subdirectory=libs/skinny

For Databricks, use the following command:

%sh curl -LsSf https://raw.githubusercontent.com/mlflow/mlflow/HEAD/dev/install-skinny.sh | sh -s pull/17744/merge

Related Issues/PRs

Fixes #17699

What changes are proposed in this pull request?

This PR fixes an issue where LLM scorers (both built-in and custom) couldn't work with Amazon Bedrock Claude models. The root cause was that the Bedrock API requires an anthropic_version field when invoking Anthropic models, which was missing from the request payload.

The fix adds the required anthropic_version field with the value "bedrock-2023-05-31" to the Bedrock Anthropic adapter's payload transformation.

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

The existing tests should cover this change. The fix ensures that the required field is always present in the payload when using Bedrock with Anthropic models.

Does this PR require documentation update?

  • No. You can skip the rest of this section.

Release Notes

Is this a user-facing change?

  • Yes. Give a description of this change to be included in the release notes for MLflow users.

This fix enables LLM scorers (such as Correctness, Guidelines, and custom prompt judges) to work correctly with Amazon Bedrock Claude models by including the required anthropic_version field in API requests.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/tracking: Tracking Service, tracking client APIs, autologging
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflows
  • area/gateway: MLflow AI Gateway client APIs, server, and third-party integrations
  • area/prompts: MLflow prompt engineering features, prompt templates, and prompt management
  • area/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionality
  • area/projects: MLproject format, project running backends
  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages

How should the PR be classified in the release notes? Choose one:

  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes

Should this PR be included in the next patch release?

  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)

🤖 Generated with Claude Code

@github-actions github-actions bot added area/evaluation MLflow Evaluation area/scoring MLflow Model server, model deployment tools, Spark UDFs rn/bug-fix Mention under Bug Fixes in Changelogs. labels Sep 16, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 16, 2025

Documentation preview for 5b2eb78 is available at:

More info
  • Ignore this comment if this PR does not change the documentation.
  • The preview is updated when a new commit is pushed to this PR.
  • This comment was created by this workflow run.
  • The documentation was built by this workflow run.

@harupy harupy changed the title Fix Bedrock Anthropic adapter by adding required anthropic_version field Fix Bedrock Anthropic adapter by adding required anthropic_version field Sep 16, 2025
@harupy harupy added the team-review Trigger a team review request label Sep 16, 2025
Copy link
Collaborator

@serena-ruan serena-ruan left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-actions github-actions bot added the v3.4.1 label Oct 7, 2025
@ravees
Copy link

ravees commented Nov 12, 2025

Hi @harupy @serena-ruan Any update on the PR merge?
Facing this issue for v3.6.0 mlflow.genai.scorers Correctness, and
Guidelines

@ravees
Copy link

ravees commented Nov 12, 2025

The below mlflow.genai.evaluate samples with "anthropic_version": "bedrock-2023-05-31" field. Can you please verify the patch solution?

## 1.Run the evaluation with parameters including anthropic_version
results = mlflow.genai.evaluate(
    data=dataset,
    predict_fn=predict_fn,
    scorers=[
        # Built-in LLM judge
        Correctness(
            model="bedrock:/global.anthropic.claude-haiku-4-5-20251001-v1:0",
            parameters={
                "temperature": 0,
                "max_tokens": 256,
                "anthropic_version": "bedrock-2023-05-31",
            },
            ),
        # Custom criteria using LLM judge
        Guidelines(name="is_english", guidelines="The answer must be in English", 
        model="bedrock:/global.anthropic.claude-haiku-4-5-20251001-v1:0",
        parameters={
                "temperature": 0,
                "max_tokens": 256,
                "anthropic_version": "bedrock-2023-05-31",
            },
        ),
    ],
)



## 2.Run the evaluation with anthropic_version
results = mlflow.genai.evaluate(
    data=dataset,
    predict_fn=predict_fn,
    scorers=[
        # Built-in LLM judge
        Correctness(
            model="bedrock:/us.anthropic.claude-3-7-sonnet-20250219-v1:0",
            anthropic_version="bedrock-2023-05-31",
            ),
        # Custom criteria using LLM judge
        Guidelines(name="is_english", guidelines="The answer must be in English", 
        model="bedrock:/us.anthropic.claude-3-7-sonnet-20250219-v1:0",
        anthropic_version="bedrock-2023-05-31",
        ),
    ],
)

This change fixes an issue where LLM scorers couldn't work with Amazon Bedrock
Claude models. The Bedrock API requires an 'anthropic_version' field when
invoking Anthropic models, which was missing from the request payload.

The fix adds the required 'anthropic_version' field with the appropriate
version string 'bedrock-2023-05-31' to ensure compatibility with Bedrock's
Anthropic model invocations.

Fixes mlflow#17699

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
The tests were failing because they were expecting request payloads without
the anthropic_version field. This commit updates the test expectations to
include the required anthropic_version field that was added to fix
compatibility with Bedrock's Anthropic API.

Signed-off-by: Harutaka Kawamura <harutaka@users.noreply.github.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
@harupy harupy force-pushed the fix-bedrock-anthropic-version branch from 108d6a0 to 7dd2904 Compare November 13, 2025 02:20
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
@harupy
Copy link
Member Author

harupy commented Nov 13, 2025

@ravees Thank for testing. I pushed 5b0d635. Can you test again?

@harupy harupy added v3.6.1 and removed v3.4.1 labels Nov 13, 2025
@harupy
Copy link
Member Author

harupy commented Nov 14, 2025

@ravees did you have a chance to test?

@ravees
Copy link

ravees commented Nov 14, 2025

Hi @harupy , tested with the new fix and it worked for bedrock antropic models like bedrock:/global.anthropic.claude-haiku-4-5-20251001-v1:0.
Which MLflow version will this fix be part of and when can we expect this to be released?
Thank you so much for the timely fix!

@harupy
Copy link
Member Author

harupy commented Nov 15, 2025

@ravees Thanks for testing! This patch will be included in the 3.7.0 release, which we’re targeting for the end of November.

@harupy harupy added this pull request to the merge queue Nov 15, 2025
Merged via the queue into mlflow:master with commit 5cdb505 Nov 15, 2025
45 checks passed
@harupy harupy deleted the fix-bedrock-anthropic-version branch November 15, 2025 02:31
jackiehimel pushed a commit to jackiehimel/mlflow that referenced this pull request Nov 21, 2025
…field (mlflow#17744)

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: Harutaka Kawamura <harutaka@users.noreply.github.com>
Signed-off-by: Jackie Himel <jacqueline.himel@vanderbilt.edu>
mprahl pushed a commit to opendatahub-io/mlflow that referenced this pull request Nov 21, 2025
…field (mlflow#17744)

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: Harutaka Kawamura <harutaka@users.noreply.github.com>
Tian-Sky-Lan pushed a commit to Tian-Sky-Lan/mlflow that referenced this pull request Nov 24, 2025
…field (mlflow#17744)

Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Signed-off-by: Harutaka Kawamura <harutaka@users.noreply.github.com>
Signed-off-by: Tian Lan <sky.blue266000@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/evaluation MLflow Evaluation area/scoring MLflow Model server, model deployment tools, Spark UDFs rn/bug-fix Mention under Bug Fixes in Changelogs. team-review Trigger a team review request v3.6.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Can't use LLM scorers with Amazon Bedrock (and probably some other model providers)

3 participants