Skip to content

[Enhancement]: Snake case response metadata in ChatBedrockConverse for consistency #975

@Liorbau

Description

@Liorbau

Package

langchain-aws

Checked other resources

  • I added a descriptive title to this issue
  • I searched the LangChain documentation with the integrated search
  • I used the GitHub search to find a similar issue and didn't find it
  • I am sure this is a bug and not a question or request for help

Example Code

# Current behavior: internal keys remain in PascalCase/camelCase
response_message = _parse_response(mock_aws_response)
print(f"Current keys: {list(response_message.response_metadata.keys())}")
# Output includes: 'ResponseMetadata', 'stopReason', 'metrics'

# Expected behavior: keys should be converted to snake_case for consistency
# e.g. 'response_metadata', 'stop_reason', 'metrics'

Error Message and Stack Trace (if applicable)

Description

Currently, ChatBedrockConverse returns some response metadata using AWS's native PascalCase or camelCase (e.g., messageStop events). This is inconsistent with LangChain's standard of using snake_case for metadata keys.

There is already a # TODO: snake case response metadata?

Proposed Solution:
Use the internal _camel_to_snake_keys utility function to recursively convert metadata keys in _parse_stream_event and _extract_response_metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions