Skip to content

Conversation

sonianuj287
Copy link

@sonianuj287 sonianuj287 commented Oct 7, 2025

This PR updates the DefaultLlmImpl class to properly parse responses from the Claude V3 family of Bedrock models. Previously, only the V2 response format (completion field) was supported. With this change, the parser now supports the V3 format (content -> text) while maintaining backward compatibility with V2.

Changes Made

  • Updated buildChatCompletionOutput():
    Detects "content" field for Claude V3 responses.
    Extracts text from the first element of the content list.
    Adds extracted text to answers.
    Added a new unit test in DefaultLlmImplTests.java:
  • testChatCompletionApiForBedrockClaudeV3()
    Mocks a V3-style Bedrock response and validates output parsing.
    Reformatted test files to satisfy Spotless formatting rules.

Why this change is needed
Claude V2 models are deprecated; V3 is the current standard.
Without this fix, requests to "bedrock/anthropic-claude" with V3 models fail to extract answers, causing RAG pipelines to break.
Ensures users don’t need to pass llmResponseField manually for default Bedrock Claude models.

How to test
Run all existing unit tests:
./gradlew clean build

resolves #4168 (comment)

@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 7, 2025 15:01 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 7, 2025 15:01 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 7, 2025 15:01 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 7, 2025 15:01 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 force-pushed the fix/claude-v3-bedrock-support branch from aa64626 to 540a52e Compare October 7, 2025 15:02
@sonianuj287 sonianuj287 had a problem deploying to ml-commons-cicd-env-require-approval October 7, 2025 15:03 — with GitHub Actions Failure
@sonianuj287 sonianuj287 had a problem deploying to ml-commons-cicd-env-require-approval October 7, 2025 15:03 — with GitHub Actions Error
@sonianuj287 sonianuj287 had a problem deploying to ml-commons-cicd-env-require-approval October 7, 2025 15:03 — with GitHub Actions Failure
@sonianuj287 sonianuj287 had a problem deploying to ml-commons-cicd-env-require-approval October 7, 2025 15:03 — with GitHub Actions Error
@sonianuj287
Copy link
Author

Hi @mingshl @rithin-pullela-aws , Could you please review my PR and suggest changes.

Thanks :)

@mingshl
Copy link
Collaborator

mingshl commented Oct 7, 2025

oh great, this is going to use the same interface string, and it will auto detect these two formats and parse accordingly. Can you also add in ITs? this is the best way we can monitor and keep track when the model interface failed.

I ran your CIs and also I added the resolved issues and link the issue in the PR descriptions.

@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 7, 2025 20:02 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 7, 2025 20:02 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 7, 2025 20:02 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 7, 2025 20:02 — with GitHub Actions Waiting
@sonianuj287
Copy link
Author

Hi @mingshl @akolarkunnu @rithin-pullela-aws , Please review the code changes and run the test CIs. I also covered the test coverage in last PR.

Copy link
Contributor

@rithin-pullela-aws rithin-pullela-aws left a comment

Choose a reason for hiding this comment

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

Thanks for raising the PR!!
Added few comments

@sonianuj287 sonianuj287 force-pushed the fix/claude-v3-bedrock-support branch from a6199dc to cbe84d8 Compare October 10, 2025 16:52
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 10, 2025 16:54 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 10, 2025 16:54 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 10, 2025 16:54 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 10, 2025 16:54 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 11, 2025 06:53 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 11, 2025 06:53 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 11, 2025 06:53 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 11, 2025 06:53 — with GitHub Actions Waiting
@sonianuj287
Copy link
Author

Hi @rithin-pullela-aws , sorry for bothering you again and again. But please if you have time to review them once and suggest me the changes, it'll keep me occupied by working on it.
Thanks :)

@sonianuj287 sonianuj287 temporarily deployed to ml-commons-cicd-env-require-approval October 13, 2025 18:14 — with GitHub Actions Inactive
@sonianuj287 sonianuj287 temporarily deployed to ml-commons-cicd-env-require-approval October 13, 2025 18:14 — with GitHub Actions Inactive
@sonianuj287 sonianuj287 temporarily deployed to ml-commons-cicd-env-require-approval October 13, 2025 18:14 — with GitHub Actions Inactive
@sonianuj287 sonianuj287 deployed to ml-commons-cicd-env-require-approval October 13, 2025 18:14 — with GitHub Actions Active
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 13, 2025 20:00 — with GitHub Actions Waiting
@sonianuj287 sonianuj287 requested a deployment to ml-commons-cicd-env-require-approval October 13, 2025 20:00 — with GitHub Actions Waiting
Copy link
Contributor

@rithin-pullela-aws rithin-pullela-aws left a comment

Choose a reason for hiding this comment

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

Small Comment about the IT.
It should simple to have the IT fixed instead of writing a new one.

We can remove the BM25_SEARCH_REQUEST_WITH_CONVO_WITH_LLM_RESPONSE_TEMPLATE from plugin/src/test/java/org/opensearch/ml/rest/RestMLRAGSearchProcessorIT.java to have the IT hit the code change

Comment on lines +132 to +134
private Map<String, Object> invokeBedrockInference(Map<String, Object> mockResponse) throws Exception {
// Create DefaultLlmImpl and mock ML client
DefaultLlmImpl connector = new DefaultLlmImpl("model_id", null); // Use getClient() from MLCommonsRestTestCase
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks more like a unit test than an integration test.
Generally in Integration tests, we make an actual call to the LLM and verify the response is as expected.

It should be something like:

GET /<index_name>/_search?search_pipeline=rag_pipeline
{
    "query": {
        "match": {
            "text": "Abraham Lincoln"
        }
    },
    "ext": {
        "generative_qa_parameters": {
            "llm_model": "bedrock/anthropic-claude",
            "llm_question": "who is lincoln",
            "system_prompt": "null",
            "user_instructions": "null",
            "context_size": 5,
            "message_size": 5,
            "timeout": 60
        }
    }
}

and we need to verify this is ITs.

This was being tested previously in the ITs, but we added a llm_response_field to get it working.

In this PR: dc8403f#diff-413a5184ffbe5b2e3f86084003df503a3b1fb86ec76ecf81ecb28ba213d67bca a new llm_response_field was added to solve the issue. We can just undo the changes in this PR to check if the ITs pass after this change.

Now that code handles it we do not need this template: https://github.com/opensearch-project/ml-commons/blob/main/plugin/src/test/java/org/opensearch/ml/rest/RestMLRAGSearchProcessorIT.java#L473C33-L492

I believe instead of these changes we can try to update the other ITs

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] Outdated Default Claude model parsing in Generative QA Processor

4 participants