Querying PyRIT memory for findings

Querying PyRIT memory turns raw red teaming runs into findings lists, evidence packs and custom reports. This page covers what the async memory API returns, when to use it, and what to plan before you build.

On this page

How to query PyRIT memory for findings

When a red team has run PyRIT against an AI system, the findings list or evidence pack has to come from what PyRIT stored, not from a summary someone remembers. PyRIT keeps conversations and results in memory, backed by SQLite or Azure SQL, and the memory API is how you read them back out. Use it when the built-in outputs do not match the question you are answering: a findings list filtered to one harm category, an evidence pack grouped by control or engagement, or a custom report that combines attack results with scores from several runs. If the built-in output already answers the question, use it and skip the custom query.

PyRIT's CentralMemory manages one shared memory instance across the framework's components, so attacks, scorers and your own code read the same records. Inside async code, use the async memory methods, such as get_conversation_messages_async, which is the current pattern for pulling the messages of a conversation. Synchronous methods still exist while they are being deprecated, so a query script written against an older example may run but will need migrating. Before you build anything, confirm which memory methods your installed version exposes in the PyRIT documentation for memory and pin the version you query against, so the report does not change when the library does.

Decide before you write the query what one finding row means: one attack, one conversation, or one objective. Confirm the fields you need, including the labels your team applied to each run, and test the query on a copy of a known engagement database where you already know the expected count. Store the query with the report so a reviewer can rerun it. Ask whether the database is in your infrastructure, who can read it, and how you will back it up, since the memory file may hold sensitive prompts and model outputs.

Which memory query path fits your reporting need

This table compares the four ways to get data out of PyRIT memory: async memory methods in custom Python, synchronous methods kept during deprecation, built-in scenario and CLI views, and CoPyRIT exports. Read each row against your reporting need and the skills your team has, then pick the lowest-effort path that still returns the fields your findings list requires.

Query pathWhat it suitsWho can run it and what it needs
Async memory methods in custom PythonCustom findings lists, joins across conversations and scores, and evidence packs with your own fields. Methods such as get_conversation_messages_async fit async code.Engineers comfortable with Python and async code. Needs a configured memory instance, a version-pinned PyRIT install and a review of the method signatures for your release.
Synchronous memory methods during deprecationExisting scripts that have not yet moved to async. Useful for short one-off pulls while a migration is in progress.Python developers maintaining older scripts. Expect deprecation warnings and a planned move to the async methods before the synchronous ones are removed.
Built-in scenario and CLI viewsQuick run summaries and comparisons across runs without writing code. Suits operators checking a scenario outcome or a regression between versions.Security testers and operators with access to the PyRIT command line. Needs the same memory location as the run and an agreed label convention to filter results.
CoPyRIT exportsReviewers who will not run Python and need conversations in a readable format for review or sign-off.Team members with CoPyRIT access. Needs a deployed CoPyRIT instance connected to the same memory store and an agreed reviewer workflow.
Custom evidence pack buildsRepeatable packs that combine findings, scores and run metadata for an assessor or internal review board.Engineers who own the query code and the evidence format. Needs version control for queries and a documented field list agreed with compliance.
Raw database access to SQLite or Azure SQLAd hoc audits or checks outside PyRIT. Useful when a reviewer needs to confirm stored records directly.Database-literate staff with read-only access. Confirm the schema for your PyRIT version before relying on it, and prefer the PyRIT methods for production reports.

Setting up a memory query workflow step by step

This sequence takes a team from an unconfigured PyRIT installation to a reporting script that reads known results from memory, checks them against a run it already understands, and ships with the report it produces.

  1. Confirm the memory backend and data location

    Start by deciding whether the runs you want to query were stored in SQLite or Azure SQL, because the backend determines where the data lives and how your script connects. The person who ran the assessments, or whoever owns the target environment, should confirm the backend and, for SQLite, the database file path. Record both in the report's header so later readers know where the evidence came from. You are done when someone other than the author can name the backend and point to the file or server holding the runs.

  2. Configure the environment and settings files

    Set credentials in ~/.pyrit/.env and settings in ~/.pyrit/.pyrit_conf so the reporting script uses the same memory configuration as the run that produced the data. Keep secrets out of the report script itself and out of version control. Check the configuration by launching Python in the same environment and confirming that the memory settings resolve to the backend and location you recorded in the previous step. If they differ, fix the configuration before writing any query.

  3. Initialize CentralMemory in the reporting script

    In the reporting script, initialize CentralMemory so every query reads from the shared memory instance that the PyRIT components use. Keep initialization in one function at the top of the script so the same setup runs each time the report is generated. Verify it by running a minimal script that opens memory and prints the backend type and the number of stored conversations, with no query logic yet. A clean run with a non-zero count confirms the connection works.

  4. Pull conversations and scores with async methods

    Write the query layer using the async memory methods, such as get_conversation_messages_async, inside an async entry point. Pull conversations for the run labels or conversation IDs you selected, then pull the scores attached to those responses. Keep the query functions small so each one returns one kind of record, which makes errors easier to isolate. Check the output by printing the first few conversations with their scores and confirming that each score links to a response in the conversation you expect.

  5. Validate counts against a known run

    Pick one run whose results you already reviewed, such as a small scenario from a recent session, and compare the script's totals against it. Check the number of conversations, messages, scored responses and attacks, and note any mismatch. A mismatch usually means the wrong backend was read, a label filter is too broad, or some responses were never scored. Do not generate the full report until the known run matches, because a wrong denominator will carry into every rate you calculate later.

  6. Version the query script with the report

    Store the query script in version control next to the report template, and record the PyRIT version, the backend and the run labels used for each report. Commit the script before generating a report that will be shared, so the findings can be regenerated from the same logic. Check the result by regenerating the report from the tagged commit and confirming that the counts match the original output. A matching rerun shows that the findings can be reproduced by someone else.

How PyRIT memory relates conversations, scores and attacks

A finding traces back through three linked records: the attack result, the conversation behind it and the scorer decision on the response. PyRIT's memory stores conversations and results in SQLite or Azure SQL, and every component in a run writes to the same shared memory instance through CentralMemory. In practice, an attack result points to the conversation that produced it, the conversation holds the ordered prompts and responses (the messages), and the scores attached to those pieces record how each response was judged. Before you build a report on this chain, confirm the exact table names, foreign keys and field names in the PyRIT version you run, since the schema is documented as part of the memory model and can change between releases.

Working through one example makes the chain concrete. Suppose a finding says a target produced disallowed content on a given objective (this is illustrative). To support it, start from the attack result for that objective, read its conversation ID, pull the conversation's messages in order, and then fetch the scores linked to the assistant response that carries the harmful content. Keep the original prompt, the converted prompt if a converter ran, the target identifier and the scorer identity together, because a reviewer will ask which prompt was sent, what came back and who or what decided it. Scorer output is a decision by an LLM, a content safety service or custom logic, so the scorer's name and configuration belong in the evidence alongside the score.

Confirm three points with your own run before trusting the relationships. First, check that a sample of attack results resolves to the conversation and the scored response you expect. Second, check how scores attach when a message has several scorers or when a scorer failed and left no value. Third, check whether memory from earlier runs is still reachable in the database you query, because labels and operations decide which records belong to a given engagement. The async methods, such as get_conversation_messages_async, are the supported route for these lookups in async code, and the synchronous equivalents remain during deprecation, so pick one pattern and apply it across the whole query script.

How a findings report flows from memory to reviewers

The flow starts with a PyRIT attack writing its conversations and scores into memory, which is backed by SQLite or Azure SQL. A reporting script then reads that memory through CentralMemory and the async memory methods, builds a findings list and an evidence pack, and hands the output to reviewers. The trust boundary around the stored conversations matters most: the raw records hold sensitive model outputs, so only the script should have direct database access, and reviewers should receive the reduced output. Check who can read the store before sharing anything.

Data path from a PyRIT run in memory to the reviewer's findings and evidence.

Protecting conversations and scores in memory

PyRIT memory holds every prompt, response and score from an engagement, and some of that content is harmful or sensitive by design. The controls below cover what gets stored, who can read it, which credentials travel with it and how long it lives, so the findings list and evidence pack can leave the team without carrying more than they should.

Treat stored harmful content as sensitive

Red teaming deliberately elicits harmful output, so the conversation tables hold material that may be unsafe to read casually. Decide which harm categories the team will store in full and which will be stored as scores only. Confirm with your security lead how operators handle this content, and mark exported packs that contain raw responses so reviewers know what they are opening.

Keep credentials out of exports

Target keys and model credentials are read from ~/.pyrit/.env, and that file must never be copied into a findings list, evidence pack or shared project folder. Check every export script for accidental inclusion of environment values or target configuration that echoes secrets. Rotate any key that appears in an export before the pack is shared.

Match database access to the engagement

Memory is typically a SQLite file or an Azure SQL database, and anyone who can open it can read every conversation in it. Grant read access only to people assigned to the engagement, and use separate databases or labeled sets for clients or business units that should not see each other's runs. Confirm that the access model matches the one agreed for the engagement before the first run.

Set retention before any report leaves

Decide how long raw conversations are kept, when run data is deleted and who approves deletion before the first report is sent. Findings may need to be retained for a remediation window while raw prompts should be removed sooner. Write the retention rule into the engagement plan so exported reports and the underlying memory follow the same schedule.

Limit what the query exports

A query for scores can accidentally return full message text, target endpoints or operator names. Select only the fields a finding needs, and review the first few exported rows by hand before the export is shared. Record which query produced each pack so the reviewer can reproduce the selection later.

Protect the pack in transit

Evidence packs are often emailed or uploaded to a ticketing system, which can copy them to places the engagement never covered. Encrypt the pack, share it through a location the client controls and limit the recipient list to named reviewers. Confirm the client's rules for transferring data that contains harmful output.

Local SQLite versus Azure SQL for reporting

A single operator running PyRIT on a laptop or a locked-down workstation usually stores memory in SQLite. PyRIT's memory layer keeps conversations and results in SQLite or Azure SQL, so the same query code can read either. For one person, SQLite is simple: the database is a local file, queries run without a network hop, and the operator controls every copy. Query access is direct, because the findings script runs on the same machine that wrote the data. Concurrency is the constraint. SQLite is built for one writer at a time, so a second process writing during a long run, or a dashboard reading while attacks are still writing, can cause lock errors. Run reporting after a scenario finishes, not during it.

  • Query access: the reporting script opens the local database file directly, with no credentials beyond file permissions on the machine.
  • Concurrency: keep one writing process per database file, and avoid running a second report against a file that is still receiving results.
  • Backup: nothing is backed up unless you copy the file. Take a dated copy of the database file after each run you need to defend later.
  • Readers: only people with access to that machine or a copied file can see findings, so shared review usually means exporting evidence by hand.
  • Retention: the file persists until deleted, so remove or archive it under your own data handling rules.

Confirm the database location and the connection setting in your ~/.pyrit/.pyrit_conf file, and check that no other process is holding the file before you query it.

What to confirm before building custom reports

A custom report built on PyRIT memory is only as reliable as the version, backend and labels underneath it. The cards below cover the checks to run in your own environment before you write queries that feed a findings list or an evidence pack.

PyRIT version and memory API surface

Confirm which PyRIT release your team runs and check the memory methods that release exposes before you write any query. Method names and return shapes can change between releases, so a script written against one version may break or quietly return different fields on another. Pin the version in your project and record it in every report so a reviewer can rerun the same query later. The memory API differs by release, so test each query against the pinned version.

PyRIT memory docs

Sync and async method status

PyRIT's CentralMemory supports async memory methods such as get_conversation_messages_async, while synchronous methods remain during a deprecation period. Check whether your release still provides the synchronous calls your scripts use and plan a move to async code before the synchronous versions are removed. Ask whether a deprecation warning is raised at runtime so the team sees it in test runs rather than in production reports.

Memory backend in use

PyRIT memory stores conversations and results in SQLite or Azure SQL, and the two backends differ in concurrency, access control and backup. Confirm which backend holds your runs and whether a team shares one instance. Check that your query scripts connect to the same store the runs wrote to, and that a read-only account can run the queries without write access. Record the backend in the report header.

Undetermined scores and errors

Find out how an undetermined score, a scorer failure or a target error is stored in results before you calculate counts. If these outcomes are saved as null values, as separate statuses or as missing rows, each choice changes the denominator of any rate and the number of findings listed. Run a small test with a known error and a known undetermined result, then confirm your query returns each one in the category you intended.

Label availability for filters

Confirm that the labels your engagement applies at run time are stored with each conversation and can be used as filters in your queries. If labels are missing or applied only in some runs, a report scoped to one engagement can silently include or exclude runs. Check the label names on a sample run and verify that a query filtered by engagement returns the same runs your team counts manually.

Access rights and evidence handling

Reports often contain prompts and model outputs that include sensitive content. Confirm who can read the memory store, where exported packs are kept and how long copies stay on shared drives. Ask whether the people who review evidence have the same access rights as the operators who ran the attacks. Document the answers, since an auditor will ask who could query the raw conversations.

Questions teams ask before querying PyRIT memory

What does it cost to query PyRIT memory for findings?

Cost depends on how many runs, targets and harm categories the findings cover, how much reporting logic has to be written, and how many people must review the output. Most of the spend is one-time: scoping the questions the report must answer, writing and testing the queries against your memory database, and building the evidence pack format. Recurring cost appears when reports are regenerated for each release or model version. A written scope should name the data sources, the output format, the number of report views and the review steps, so that a quote can be compared line by line with an internal estimate. DeployOpen does not publish prices, and a quote follows from that written scope.

How long does it take to build a findings query and evidence pack?

Duration is driven by scope rather than by the query language itself. A single findings list filtered by one label and one harm category is a small task. An evidence pack that joins conversations, scores, labels and run metadata across several engagements, and that must match a reviewer's format, takes longer because each join and each field needs checking against real records. Ask for the timeline to be tied to named deliverables and to a test pass on a sample of your own memory data. Any duration you are given should trace back to that scope, and you should ask which assumptions about data volume and label quality it depends on.

What must our team provide before the work starts?

Three inputs decide most of the early effort. First, access to the PyRIT memory database or a copy of it, along with the run data and the labels used to separate engagements, operators and target versions. Second, schema access or a written description of the tables and fields, so queries reflect how your runs were stored. Third, sign-off on the harm categories and the definition of a successful attack, since these decide what the findings list contains. Ask your team to confirm which memory backend each environment uses, because SQLite and Azure SQL are both supported, and to name the people who will review the output before any report leaves the team.

Can an in-house engineer query PyRIT memory using the documentation?

Yes, a Python engineer who is comfortable with async code can write memory queries using the published documentation. PyRIT's CentralMemory manages a shared memory instance across components, and async methods such as get_conversation_messages_async are used in async code, while synchronous methods remain available during deprecation. The main risks for an in-house team are not the calls themselves but the interpretation: undetermined scores, failed runs, duplicated conversations across labels and mixed harm categories can all distort a findings list. Plan a review step where someone who knows the attack design checks the output against a sample of raw conversations before the findings are shared.

How do we keep memory queries working across PyRIT upgrades?

Keep the queries in version control, pin the PyRIT version each report was built against, and run a regression check on a fixed sample of known runs whenever the package is upgraded. Breaking changes between PyRIT releases have affected attack and scoring APIs, so a query that reads fields through those layers can change behavior even when it still runs. The PyRIT documentation for each release, including the 1.1.0 memory page, should be read before an upgrade. Ask any partner to state how they will handle upgrade testing and whether the retest is part of the fixed scope or a separate retainer.

Who is responsible for the accuracy of the findings report?

Accuracy is shared, and the contract should say who signs off on what. The query author is responsible for correct joins and filters, the test lead for the attack and scoring logic, and the client for the harm categories and acceptance criteria. DeployOpen prepares evidence and findings for compliance assessments but does not issue audit reports, attestations or certifications, and an independent auditor or certification body makes those decisions. If the report will feed a compliance review, ask how each figure can be traced back to a memory record so an auditor can follow it.

How DeployOpen scopes and delivers memory reporting

DeployOpen treats memory queries as part of the red teaming record, not an afterthought. We agree in writing which conversations, scores and attack results the findings list and evidence pack must cover, then build and document the query layer against your own PyRIT memory database.

How we scope

  • Engagements are fixed-scope, with the findings list, evidence fields and report format agreed in writing before work starts.
  • We confirm which PyRIT memory backend you run, SQLite or Azure SQL, and where the database is stored.
  • Scope names the labels, runs and date ranges the queries must separate, so results from different engagements stay distinct.

How we build

  • We write async queries against PyRIT memory, using the documented memory methods such as get_conversation_messages_async.
  • Queries are tested against sample runs to confirm that scores, attack results and conversations join correctly.
  • Export scripts produce the findings list and evidence pack in the formats your reviewers and auditors have requested.

How we hand over

  • You receive the query code, a run guide and documentation of every field the reports use.
  • We record which PyRIT version the queries were written and tested against, so later upgrades can be checked.
  • Handover includes a walkthrough with your security and compliance reviewers on reading the outputs.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers, including checks when PyRIT changes its memory API.
  • Support can cover new report fields, additional labels and reruns of the query set against new scenario results.
  • Ask for the support terms, response expectations and upgrade handling in the written quote before the engagement begins.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.