Skip to content

Metadata filters crash on keys containing dots or other special characters #3179

Closed

Description

Describe the bug

Filtering seeds or message pieces by a prompt_metadata key that contains a dot (or any character outside a plain SQL bind name, like a hyphen or a space) crashes the query instead of filtering.

In sqlite_memory.py and azure_sql_memory.py, _get_seed_metadata_conditions and _get_message_pieces_prompt_metadata_conditions build the SQL with the key interpolated into both the JSON path and the bind parameter name:

f"JSON_EXTRACT(prompt_metadata, '$.{key}') = :{key}"

For a key like a.b, SQLAlchemy parses :a.b as a parameter named a followed by literal text, so the later bindparams() call raises ArgumentError: This text() construct doesn't define a bound parameter named 'a.b'.

This is the same class of problem #3063 fixed for memory labels, where the accepted fix quotes the JSON path and uses indexed parameter names.

Steps/Code to Reproduce

import asyncio, tempfile
from pyrit.memory.sqlite_memory import SQLiteMemory
from pyrit.models import SeedPrompt

async def main():
    memory = SQLiteMemory(db_path=tempfile.mktemp(suffix=".db"), verbose=False)
    await memory.add_seeds_to_memory_async(seeds=[
        SeedPrompt(value="dotted", data_type="text", dataset_name="t", metadata={"a.b": "v1"}),
    ], added_by="repro")
    got = await memory.get_seeds_async(metadata={"a.b": "v1"})  # raises ArgumentError
    print(got)

asyncio.run(main())

Expected Results

The filter matches the stored seed by the literal metadata key a.b and returns it.

Actual Results

sqlalchemy.exc.ArgumentError: This text() construct doesn't define a bound parameter named 'a.b'

Screenshots

N/A

Versions

OS: macOS
Python version: 3.14
PyRIT version: installed from main (66c41fa)

Activity

  1. ManoharPaturi commented on Oct 15, 2026

    @ManoharPaturi
    ContributorAuthor

    Main now has literal key matching for metadata filters on both backends from #3125, so the crash and the mismatch described here are resolved there. Closing the fix PR that predates it.

  2. romanlutz commented on Oct 20, 2026

    @romanlutz
    Contributor

    Fixed by #3125, which adds literal metadata-key matching for SQLite and Azure SQL. #3180 adds regression coverage for special-character keys, retrieval, and seed/group removal. Both PRs are merged into main. Closing as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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