Red teaming Azure OpenAI and Microsoft Foundry deployments with PyRIT

Point PyRIT's OpenAI chat target at your Azure OpenAI or Foundry endpoint, authenticate with Entra ID, and run attacks against deployments with content filters enabled.

On this page

How PyRIT reaches Azure OpenAI and Foundry deployments for red teaming

A security team usually reaches this step because a deployment is already live or scheduled to go live, and someone needs evidence of how it behaves under attack with its content filters switched on. In PyRIT, the integration point for that work is the OpenAI chat target, which is pointed at the deployment's endpoint through the OPENAI_CHAT_ENDPOINT setting. PyRIT's quick start documents three endpoint shapes: api.openai.com for OpenAI-hosted models, cognitiveservices.azure.com project endpoints, and services.ai.azure.com OpenAI endpoints for Microsoft Foundry projects. Confirm which shape your resource exposes before writing any configuration, because a project endpoint and an OpenAI-style endpoint for the same deployment can differ in path and in how the model name is supplied. The target is the objective side of the test: it is the model under evaluation, and it must be the deployment your users actually reach, not a playground copy with different filter settings.

Before any attack runs, record the deployment name, the API version your application uses, the content filter policy attached to the deployment, and whether any custom blocklists or prompt shields apply. These settings decide what the results mean. Ask the platform owner for the filter configuration in writing, and check it again after any change, since a later edit can alter the behavior you tested. Keep the target configuration in version control or the team's configuration store so each PyRIT run can be tied back to a known endpoint and filter state. Authentication for these endpoints is covered in the setup section, where Entra ID replaces API keys.

This section covers only how PyRIT connects to the deployment. It does not choose attacks, define the harm objectives, or decide whether a response counts as a failure. Those decisions sit with the attack strategies, scoring and datasets sections of this guide. Keeping the target setup separate from those choices makes it easier to show an assessor exactly which system was tested and how the results were produced.

What the team needs before the first attack runs

Most delays in a first PyRIT run on Azure OpenAI or Foundry come from missing prerequisites rather than from the attack itself. The items below cover the runtime, the PyRIT version, the Azure resources and identity, the network path and the storage plan, and each one should be confirmed before the team schedules testing.

Supported Python runtime

PyRIT installs with pip, and the PyPI package supports Python 3.10 up to but not including 3.15. The PyRIT documentation recommends Python 3.13, so the test host should run that version unless your own tooling requires otherwise. Confirm the interpreter on the exact host or container image that will run the attacks, since a mismatch surfaces as an install failure rather than a test result.

PyRIT docs

Pinned PyRIT version

Pin the PyRIT release you tested rather than installing whatever pip resolves on the day of the run. PyRIT v1.1.0 was released on 4 September 2026, and the scoring and CoPyRIT behavior changed across the 1.x line. Record the version in your test plan so that a later rerun can be compared with the original results and any finding can be reproduced.

PyRIT releases

Azure OpenAI or Foundry project

Confirm that the target Azure OpenAI resource or Foundry project has a deployed model, and record the deployment name and the endpoint PyRIT will call. PyRIT's quick start distinguishes between cognitiveservices.azure.com project endpoints and services.ai.azure.com OpenAI endpoints, so copy the endpoint format from the current documentation for your resource type. Ask the platform owner which deployment is production-equivalent, because testing a different model version produces different findings.

OpenAI chat target docs

Entra ID identity and role

Plan to authenticate with an Entra ID identity instead of an API key, so that access is tied to a reviewable principal and can be removed centrally. Grant that identity the data-plane role on the specific resource that allows model inference, and nothing broader. Confirm the exact Azure role names and the scope assignment with Microsoft's current documentation, because role names change across Azure OpenAI and Foundry, and record who approved the assignment.

Network path to the endpoint

Confirm that the test host can reach the Azure endpoint over the network path your organization permits, including any private endpoint, firewall allow list or proxy. If the resource is restricted to a virtual network, the test host must sit inside that network or be routed through it. Test connectivity with a single benign prompt before the first attack, so that a blocked route is not mistaken for a model refusal or a content filter block.

Scorer and memory store plan

Decide where scorers run and where results are stored before the first attack. Scorers can call an LLM, Azure AI Content Safety or custom logic, and memory can be SQLite or Azure SQL. Name the scorer model and its endpoint, state whether it is separate from the target, and choose a memory location with access control and retention that match your data handling rules, so that the record of each attack is preserved for review.

Configuring the OpenAI chat target against an Azure endpoint

This sequence takes a PyRIT installation from a clean virtual environment to a verified connection to an Azure OpenAI or Foundry deployment, with Entra ID authentication and content filters confirmed before any adversarial prompt is sent. Each step ends with a check so the team knows the target works before it is trusted for testing.

  1. Install PyRIT in a virtual environment

    The engineer creates a dedicated Python virtual environment and installs PyRIT from PyPI with pip. The PyPI package supports Python 3.10 up to but not including 3.15, and the PyRIT documentation recommends Python 3.13, so confirm the interpreter version before installing. Keeping PyRIT in its own environment makes the version under test reproducible for later reviews. The step is done when importing the package in Python succeeds and the installed version is recorded in the test notes.

  2. Identify the endpoint shape and deployment name

    The engineer confirms which kind of endpoint the deployment exposes, since PyRIT's quick start lists separate OPENAI_CHAT_ENDPOINT forms for the public OpenAI API, Azure cognitive services project endpoints, and services.ai.azure.com OpenAI endpoints. Copy the endpoint exactly as shown in the Azure portal or Foundry project, and note the model or deployment name the application calls. Do not assume the two names match. The step is done when the team has written down one endpoint value and one deployment name, each traced to the resource that owns them.

  3. Store endpoint and model settings locally

    The engineer places the endpoint and model variables in ~/.pyrit/.env and sets non-secret defaults in ~/.pyrit/.pyrit_conf, which PyRIT reads at startup. Keep the file out of source control and limit read access to the testing account on the workstation or test host. The check is a fresh Python session that loads PyRIT and reports the endpoint value it resolved, without printing any secret. If the value differs from the one recorded in the previous step, correct the file before continuing.

  4. Configure Entra ID token authentication

    The engineer switches the target from a static API key to Microsoft Entra ID token authentication, so no long-lived key sits in the configuration. The identity used for testing needs a role on the Azure OpenAI or Foundry resource that permits inference calls, and the team should confirm that role assignment with the resource owner rather than assume it. Local sign-in through the Azure CLI or another supported credential is the usual path for a tester. The check is that the target obtains a token and reaches the deployment without any key being set.

  5. Send one benign test prompt

    The engineer sends a harmless prompt, such as a request for a one-sentence definition of a common word, through the OpenAI chat target and reads the reply. This confirms network reachability, authentication, deployment name and API version handling in one call. If the call fails, check the error against the endpoint shape, the role assignment and the deployment name before changing anything else. The check is a successful, readable response from the named deployment.

  6. Confirm the response is recorded in memory

    The engineer queries PyRIT memory to find the conversation created by the test prompt, including the request, the response, the target identifier and the timestamp. PyRIT stores conversations in SQLite by default or in Azure SQL when configured, so the team should confirm which backend holds the record. The check is that the test conversation appears in memory with the correct target and model details. This record becomes the baseline for later evidence and for debugging any future mismatch.

  7. Verify content filters before adversarial testing

    Before any adversarial prompt is sent, the engineer confirms with the resource owner or in the Azure portal that the content filter policy attached to this deployment is enabled, and records the policy name and its configured categories and severity thresholds. Testing a deployment with filters off measures a different system from the one in production, so the record must state the filter state being tested. The check is a written configuration note, dated and attached to the test record, showing filters on for the target deployment.

Why Entra ID instead of API keys for the target

Entra ID tokens are the better default for the target, but only if you verify what they actually grant. An API key is simple to configure: one value, placed in ~/.pyrit/.env, and PyRIT works. The cost is that the key is long-lived, is not tied to a named person or workload, and tends to be copied into notebooks, CI variables and shared files, so nobody can say later who used it or when. Entra ID authentication ties each run to an identity that your directory administrators can review, disable and scope with a role. It also fits the controls your security team already uses for Azure: Key Vault for storage, Azure activity and audit logs for traceability, and conditional access policies for the sign-in path. The trade-off is setup effort and a dependency on identity configuration, which is worth it for any deployment that will be reviewed by others.

Before you switch, confirm three things with your Azure administrator. First, which identity PyRIT runs as: a user, a service principal or a managed identity, and whether anyone shares it across team members. Second, whether the role assigned to that identity grants inference only, such as the Cognitive Services OpenAI user role on the deployment, and not management rights over the resource or subscription. Third, how tokens are refreshed during long multi-turn runs. Attack strategies can run for a long time, so check the token lifetime and confirm that the token configuration keys your PyRIT version uses for authentication are taken from the PyRIT OpenAI Chat Target documentation for the 1.1.0 release, not from older examples or blog posts. Test a run that exceeds one token lifetime before you rely on it.

Keep the identity configuration out of ~/.pyrit/.env. That file should hold only the non-secret values, such as the endpoint and deployment name, and the team should store anything sensitive in Key Vault or in the environment of the runner that uses a managed identity. Confirm that no key remains in the file once the Entra ID path works, because a leftover key will keep working and defeats the review. Ask your team to document which identity owns each scanning environment and who can change its role assignments, so that a departure or a rotation does not silently break or widen access.

How a red team request travels from PyRIT to a filtered deployment

The flow starts on the test host, where PyRIT builds each attack prompt and asks Entra ID for a token instead of using a stored key. The prompt then crosses into the Azure OpenAI or Foundry endpoint, where the deployment's content filters apply before the model replies. The reply returns to PyRIT, which writes the conversation and scores into memory. Check that the token is scoped to the right resource, that filters are enabled on the tested deployment, and that memory stays inside your boundary.

Request path from the PyRIT test host through Entra ID and a filtered deployment, with memory kept in the team boundary.

Hardening the test path and protecting the evidence

A PyRIT run against Azure OpenAI or Foundry touches live model endpoints, credentials and stored conversations that may contain harmful outputs. The cards below cover the access, environment, filter, secret, storage and capacity controls that keep the test path safe and the evidence defensible.

Least-privilege Entra ID roles

Grant the identity running PyRIT only the role needed to call the chat deployment, not subscription-wide Contributor or Owner rights. Use a dedicated service principal or managed identity for the test runner, and separate the people who can change deployments from those who run attacks. Check the role assignments at the resource or project scope, and confirm which data-plane role your Foundry project requires for the endpoint you target.

OpenAI chat target docs

Separate test and production deployments

Point PyRIT at a non-production deployment whose model version, content filter and rate limits match what users reach, and never at a live customer-facing deployment. Attacks produce high volumes of adversarial traffic that can skew production logs, trigger abuse monitoring and consume quota. Document which deployment name each run used so results can be tied to the exact configuration under test.

Content filter configuration as evidence

Record the content filter policy, its severity thresholds and any custom blocklists attached to the deployment, with the time of each test run. A result that says a jailbreak succeeded is only meaningful against a known filter state, so export the configuration alongside the scan output. Confirm with your Azure administrator how filter changes are logged and who approves them.

No credentials in files

Keep API keys and endpoints out of repositories and shared notebooks. PyRIT reads credentials from ~/.pyrit/.env, which must be protected by file permissions and excluded from version control. Prefer Entra ID token authentication over static keys, and where keys are unavoidable, load them from a secrets manager at run time and rotate them after team changes.

Memory access controls

PyRIT stores conversations and scores in SQLite or Azure SQL, and those records can contain harmful model outputs. Restrict read access to the memory database to the red team, encrypt the storage at rest, and set a retention period that your evidence policy allows. Decide who may export transcripts, since exported files leave the controls of the database.

Rate limits for shared capacity

Set concurrency and request limits so an attack run does not exhaust the tokens per minute quota that other teams or production workloads share. Start with conservative settings, watch throttling responses, and schedule large campaigns outside peak hours. Confirm the quota assigned to the test deployment with your Azure administrator before the first full run.

Endpoint, identity and configuration values mapped to PyRIT

This table maps each value your Azure OpenAI or Foundry setup produces to the PyRIT setting that consumes it. Confirm every exact field name against the PyRIT 1.1.0 documentation before you write configuration, because the names are the part most likely to differ from what you remember.

System valuePyRIT field or locationWhat to confirm
Endpoint URLOPENAI_CHAT_ENDPOINTUse the form the 1.1.0 quick start shows for your endpoint type: a cognitiveservices.azure.com project endpoint or a services.ai.azure.com OpenAI endpoint
Deployment or model nameModel or deployment setting on the OpenAI chat targetMatch the deployment name you created in Azure, which can differ from the underlying model name
Entra ID identityAuth setting on the chat target, with no API key storedConfirm the exact auth option name and the identity types it accepts in the target documentation
API key (fallback only)Key variable in ~/.pyrit/.envRestrict to a test deployment and rotate it, since keys sit in a plain file on the tester's machine
Subscription and resource groupNot a PyRIT field; recorded in your test plan and run notesUse a non-production subscription or resource so attack traffic and logs stay separate from live workloads
Content filter configurationNot a PyRIT field; set on the deployment in AzureRecord the filter policy name and version used for each run, since results depend on it
Memory locationSQLite file path or Azure SQL connection in PyRIT settingsSQLite suits a single tester; Azure SQL suits shared team records. Confirm the setting name in ~/.pyrit/.pyrit_conf
Settings and secrets file~/.pyrit/.env for credentials, ~/.pyrit/.pyrit_conf for settingsKeep credentials out of source control and out of shared run logs

Questions teams ask before testing Azure OpenAI or Foundry with PyRIT

What drives the effort of red teaming Azure OpenAI or Foundry with PyRIT?

The effort follows four variables: how many deployments you need to test, which identity model your organization uses for Azure access, how the content filters are configured on each deployment, and what network path PyRIT has to the endpoint. Each deployment is a separate objective target with its own filter settings, so a set of ten models is not one test. Entra ID access means role assignments must be planned across subscriptions and resource groups. Private endpoints or restricted networks add routing and DNS work before the first prompt is sent. Ask for a list of deployments, their filter configurations and the network path before agreeing on scope.

How long does setup take if access approvals are slow?

Access approvals usually decide the schedule more than the PyRIT work itself. Setup depends on how quickly your team can grant a test identity access to the Azure OpenAI or Foundry project, approve the network path, and provide a non-production deployment to test against. Once those are in place, the install and configuration steps are short and well defined. Before committing to dates, confirm who approves subscription access, role assignments and network changes, and how long each approval takes in your organization. A written scope should list these approvals as dependencies so delays are visible early.

Can our team run PyRIT against Azure OpenAI alone?

Yes, a team with Python experience and Azure administration skills can usually do it alone, and the PyRIT documentation covers the OpenAI chat target and the endpoint formats for Azure project and services.ai.azure.com OpenAI endpoints. The harder parts are usually the identity and network setup, and deciding what a meaningful test looks like for your use case. Work that often gets underestimated includes scoring results, deciding which harms to test, and keeping memory records that someone else can review later. If you want an outside check of the setup before relying on it, a fixed-scope engagement can cover that without taking over your internal process.

What does the work need from our team?

Your team provides access and decisions, and DeployOpen does the configuration and testing inside your environment. The usual requirements are:

  • A subscription or resource group where the test identity can be granted the roles it needs on the Azure OpenAI or Foundry project.
  • A non-production deployment or a test environment with its content filters set as they are in production.
  • A named owner who signs off on the objectives and prompts before they are sent to the model.
  • Someone who can confirm network access and approve changes to firewall or private endpoint rules.

Ask your DeployOpen contact to list these items in the written scope so each has an owner and a date.

Does a fixed-scope engagement cover the content filter testing too?

A fixed-scope engagement covers what is written in the agreed scope, and filter testing is included only if your scope names it. A typical written scope lists the deployments in question, the identity model, the filter settings to be kept on during testing, the PyRIT targets and scorers to be configured, the attack categories to be run, the memory storage choice, and the deliverables such as configuration notes and a findings summary. Deliverables are agreed in writing before work starts. Ask for the scope to state exactly which filter configurations are tested with filters on, and what is excluded. DeployOpen does not issue audit reports or certifications for the results.

Should we use Entra ID or API keys for the PyRIT target?

Entra ID is usually the better fit for organizations that already manage access through Azure roles, because it avoids storing long-lived keys in files and lets access be reviewed and removed centrally. API keys are simpler to set up but need a secure store, rotation and a plan for revocation. PyRIT reads credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf, so the choice affects what goes into those files. Confirm with your security team which identity model they require, and check the PyRIT documentation for the current authentication options for the target you choose before you commit to one.

What are the common things that go wrong on the first run?

The most frequent problems are endpoint format mistakes, missing role assignments, and filters that behave differently from what the team expected. An endpoint that works in one portal may need a different OPENAI_CHAT_ENDPOINT format for a Foundry project than for a classic Azure OpenAI resource, so check the quick start formats in the PyRIT documentation. Role assignments may apply at a different scope than the one the test runs in. Filters may also block prompts that the team expected to reach the model, which produces results that look like safe behavior but are really filter activity. Record the filter settings alongside every run so results can be read correctly later.

How DeployOpen scopes and delivers Azure OpenAI red teaming

DeployOpen plans PyRIT red teaming of Azure OpenAI and Microsoft Foundry deployments as a fixed-scope engagement. The written scope fixes which endpoints, content filter settings and authentication paths are tested, and what the client receives at the end.

How we scope

  • Scope agreed in writing before work starts, listing each Azure OpenAI or Foundry endpoint to be tested.
  • Written scope records whether content filters are enabled and which filter configurations are in play.
  • Authentication method is confirmed up front, with Entra ID or key-based access documented for each target.

How we build

  • Configure the OpenAI chat target against the endpoint your team confirms, with credentials held outside source control.
  • Run objective, adversarial and scoring model roles against the deployments and filters named in scope.
  • Record every conversation and result in PyRIT memory so each finding can be traced back to its run.

How we hand over

  • Findings report describes each issue, the evidence behind it and the deployment and filter setting involved.
  • Fixes are recommended per finding, with configuration changes documented for your platform team.
  • A retest confirms whether each fix holds against the same objectives and attack strategies.

How we support

  • Engagements are fixed-scope, and ongoing support, upgrades and continuous testing are available as a retainer.
  • Retainers can cover re-running tests after deployment, model or content filter changes.
  • Confirm with DeployOpen which PyRIT version and Python runtime the retainer will track before signing.

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.