Skip to content

Comments

fix: use self.comprehend_client consistently in ComprehendFilterAgent#427

Open
themavik wants to merge 1 commit intoawslabs:mainfrom
themavik:fix/359-comprehend-filter-agent-client
Open

fix: use self.comprehend_client consistently in ComprehendFilterAgent#427
themavik wants to merge 1 commit intoawslabs:mainfrom
themavik:fix/359-comprehend-filter-agent-client

Conversation

@themavik
Copy link

@themavik themavik commented Feb 11, 2026

Summary

ComprehendFilterAgent raises AttributeError: 'ComprehendFilterAgent' object has no attribute 'comprehend_client' when instantiated without providing a custom client in options.

Root Cause

In __init__, when options.client is None, the boto3 Comprehend client is assigned to self.client instead of self.comprehend_client:

# Before (broken)
if options.client:
    self.comprehend_client = options.client  # correct
else:
    if options.region:
        self.client = boto3.client(...)  # BUG: wrong attribute name
    else:
        self.client = boto3.client(...)  # BUG: wrong attribute name

All downstream methods (detect_sentiment, detect_pii_entities, detect_toxic_content) reference self.comprehend_client, so any agent created without a pre-built client immediately fails.

Fix

Changed both else branches to assign to self.comprehend_client:

if options.client:
    self.comprehend_client = options.client
else:
    if options.region:
        self.comprehend_client = boto3.client(
            'comprehend',
            region_name=options.region or os.environ.get('AWS_REGION')
        )
    else:
        self.comprehend_client = boto3.client('comprehend')

Test Plan

  • Instantiate ComprehendFilterAgent with client=None and a region — no longer raises AttributeError
  • Instantiate with client=None and no region — uses default boto3 region, no error
  • Instantiate with a custom client — behavior unchanged

Fixes #359

When `options.client` is None, the `__init__` method was incorrectly
assigning the boto3 client to `self.client` instead of
`self.comprehend_client`. All downstream methods (`detect_sentiment`,
`detect_pii_entities`, `detect_toxic_content`) reference
`self.comprehend_client`, causing an `AttributeError` at runtime.

Changed both `else` branches to assign to `self.comprehend_client`
so the attribute name is consistent regardless of whether a custom
client is provided or one is created internally.

Fixes awslabs#359
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: Comprehend filter agent - no client exception

1 participant