Skip to content

Type inconsistency in EventMetadataFilter TypedDict #240

@jariy17

Description

@jariy17

Description

In src/bedrock_agentcore/memory/models/filters.py, the EventMetadataFilter TypedDict defines operator: OperatorType (an enum), but the actual value stored is a string.

class EventMetadataFilter(TypedDict):
    left: LeftExpression
    operator: OperatorType  # Type says enum
    right: Optional[RightExpression]

The build_expression method correctly converts the enum to a string:

filter = {"operator": operator.value}  # Stores string, not enum

Ramifications

  1. Type hint is misleading - The TypedDict suggests operator holds an OperatorType enum, but it actually holds a string like "EQUALS_TO"

  2. Potential runtime error - If a user follows the type hint and passes an enum directly (without using build_expression), boto3 will fail to serialize it since enums are not JSON serializable

  3. Type checker inconsistency - Static type checkers like mypy may produce warnings or miss actual type errors due to this mismatch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions