Skip to content

Fix bedrock anthropic models to use system field#3438

Merged
parshvadaftari merged 3 commits intomem0ai:mainfrom
acarbonetto:acarbo/fix_bedrock_models
Sep 10, 2025
Merged

Fix bedrock anthropic models to use system field#3438
parshvadaftari merged 3 commits intomem0ai:mainfrom
acarbonetto:acarbo/fix_bedrock_models

Conversation

@acarbonetto
Copy link
Copy Markdown
Contributor

@acarbonetto acarbonetto commented Sep 9, 2025

Description

Using bedrock against an anthropic model caused errors (see #3378). When using anthropic models, the system prompts were being ignored, and the response wasn't being returned in the proper format (causing errors). Anthropic models take a separate system field when passing messages, which is now being used. See: https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/system-prompts

Fixes #3378

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Please delete options that are not relevant.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • 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
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Made sure Checks passed

Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
Copy link
Copy Markdown
Contributor

@parshvadaftari parshvadaftari left a comment

Choose a reason for hiding this comment

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

Please check the comments and incorporate the requested changes.

@@ -0,0 +1,96 @@
from mem0 import Memory
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not required for the tests file. Please remove it.

Copy link
Copy Markdown
Contributor Author

@acarbonetto acarbonetto Sep 10, 2025

Choose a reason for hiding this comment

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

Yes. Will remove this test file.
Removed under 6c15e6d

raise RuntimeError(f"Failed to generate response: {e}")

@staticmethod
def _convert_tools_to_converse_format(tools: List[Dict]) -> List[Dict]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this fix it for all the LLM providers?

Copy link
Copy Markdown
Contributor Author

@acarbonetto acarbonetto Sep 10, 2025

Choose a reason for hiding this comment

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

It works for the anthropic llm models I tested. This should only affect the bedrock provider.
I'm not able to get amazon (e.g. nova-lite) models to work with either the released branch or this branch (I get a different error). So I'm not sure they are supported yet...?
Same story for openai's gpt-oss-120b model - but different error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So this fix resolves the error with the different providers? or specifically for anthropic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

specifically for anthropic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool then looks good to me. Will be releasing the fix for AWS issue with other models. It's difficult to recreate it neverthless will update it.

Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
Copy link
Copy Markdown
Contributor

@parshvadaftari parshvadaftari left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@parshvadaftari parshvadaftari merged commit 9e5810d into mem0ai:main Sep 10, 2025
6 of 7 checks passed
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
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.

Amazon Bedrock returns "Parameter validation failed" error

2 participants