Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Description

Fixes AWS Bedrock instrumentation crash when using ARN or cross-region model IDs that contain multiple dots. The issue occurred in patch_converse_stream and patch_converse functions where modelId.split(".") assumed exactly 2 parts, but ARNs and cross-region IDs have multiple dots, causing ValueError: too many values to unpack (expected 2).

Problem:

# This fails with ARNs like: arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-3-haiku-20240307-v1:0
(vendor, _) = modelId.split(".")  # ValueError: too many values to unpack

Solution:
Replaced the problematic split calls with the existing robust parse_vendor_and_model_name_from_model_id() function that already handles ARNs correctly and is used consistently in other methods like patch_invoke_model.

Changes Made

  • src/langtrace_python_sdk/instrumentation/aws_bedrock/patch.py:
    • Line 110: Replace (vendor, _) = modelId.split(".") with vendor, _ = parse_vendor_and_model_name_from_model_id(modelId) in patch_converse_stream
    • Line 145: Same replacement in patch_converse function

Key Review Points

⚠️ Critical for reviewer to verify:

  1. Test with actual ARN formats: The existing test suite covers the parser function, but please test the full instrumentation pipeline with:

    • arn:aws:bedrock:us-east-1:<account_id>:inference-profile/us.anthropic.claude-3-haiku-20240307-v1:0
    • us.anthropic.claude-sonnet-4-20250514-v1:0
  2. Behavioral consistency: Confirm that parse_vendor_and_model_name_from_model_id() returns compatible values for all model ID formats that the original split logic handled

  3. Run existing test suite: I couldn't run the full test suite locally due to missing dependencies, so please verify no regressions with:

    python -m pytest src/tests/aws_bedrock/ -v

Testing Evidence

Created test script that reproduces the original error:

Testing model_id: arn:aws:bedrock:us-east-1:123456789012:inference-profile/us.anthropic.claude-3-haiku-20240307-v1:0
  ERROR with original method: too many values to unpack (expected 2)

Testing model_id: us.anthropic.claude-sonnet-4-20250514-v1:0  
  ERROR with original method: too many values to unpack (expected 2)

Checklist for bug fix:

  • Identified root cause of the ValueError
  • Used existing robust parser instead of creating new logic
  • Made changes consistent with other methods in the same file
  • Preserved original variable naming and unpacking pattern
  • ⚠️ Needs reviewer: Full test suite execution with dependencies
  • ⚠️ Needs reviewer: End-to-end testing with actual AWS Bedrock calls

Link to Devin run: https://app.devin.ai/sessions/9b326f6380504040bf8b711ce512ab94
Requested by: karthik@scale3labs.com

Risk Assessment: Low-risk change (2 lines) but affects core functionality. The existing parser is well-tested, but human verification of compatibility is essential since I couldn't run the full test suite locally.

- Replace modelId.split('.') with parse_vendor_and_model_name_from_model_id
- Fixes crash when using ARN or cross-region model IDs with multiple dots
- Makes patch_converse and patch_converse_stream consistent with other methods

Resolves ValueError: too many values to unpack (expected 2) when using:
- ARN format: arn:aws:bedrock:us-east-1:<account_id>:inference-profile/us.anthropic.claude-3-haiku-20240307-v1:0
- Cross-region format: us.anthropic.claude-sonnet-4-20250514-v1:0

Co-Authored-By: karthik@scale3labs.com <karthik@scale3labs.com>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Co-Authored-By: karthik@scale3labs.com <karthik@scale3labs.com>
@karthikscale3 karthikscale3 merged commit b1963ef into development Jul 24, 2025
0 of 4 checks passed
@karthikscale3 karthikscale3 deleted the devin/1753390206-fix-bedrock-arn-parsing branch July 24, 2025 20:57
karthikscale3 added a commit that referenced this pull request Jul 24, 2025
* capture different types of google genai inputs (#534)

Co-authored-by: Obinna Okafor <obinna.okafor01@gmail.com>

* Read stream before saving attributes. Parse modelId in a more robust way.

* Decide based on model name on the set of attributes tracked.

* Added basic test for model ID parsing.

* Added replay tests for AWS Bedrock.

* Added test for streaming requests too.

* Obinna/fix awsbedrock streaming response (#538)

* fix aws bedrock streaming bug

* bump version

* add deprecated dependency

* restrict current pinecone instrumentation to v6.0.2

* hard code boto3 dependency version

* fix duplicate event stream

* set test aws key

* Fix AWS Bedrock ARN parsing issue in converse methods (#544)

* Fix AWS Bedrock ARN parsing issue in converse methods

- Replace modelId.split('.') with parse_vendor_and_model_name_from_model_id
- Fixes crash when using ARN or cross-region model IDs with multiple dots
- Makes patch_converse and patch_converse_stream consistent with other methods

Resolves ValueError: too many values to unpack (expected 2) when using:
- ARN format: arn:aws:bedrock:us-east-1:<account_id>:inference-profile/us.anthropic.claude-3-haiku-20240307-v1:0
- Cross-region format: us.anthropic.claude-sonnet-4-20250514-v1:0

Co-Authored-By: karthik@scale3labs.com <karthik@scale3labs.com>

* Bump version to 3.8.21 for ARN parsing bug fix

Co-Authored-By: karthik@scale3labs.com <karthik@scale3labs.com>

---------

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: karthik@scale3labs.com <karthik@scale3labs.com>

---------

Co-authored-by: obinnascale3 <109410793+obinnascale3@users.noreply.github.com>
Co-authored-by: Obinna Okafor <obinna.okafor01@gmail.com>
Co-authored-by: m1kl0sh <miklos.erdelyi@moduscreate.com>
Co-authored-by: Obinna Okafor <obinna@scale3labs.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: karthik@scale3labs.com <karthik@scale3labs.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.

1 participant