Red teaming Azure Machine Learning endpoints with PyRIT

A practical guide to testing models on Azure Machine Learning managed online endpoints with PyRIT's AzureMLChatTarget, from endpoint and key variables to multi-turn attacks and evidence.

On this page

Red teaming Azure Machine Learning endpoints with PyRIT: what the integration does

A team that hosts a model on an Azure Machine Learning managed online endpoint and needs adversarial testing can point PyRIT at that endpoint with the built-in AzureMLChatTarget. The target sends prompts to the endpoint and, by default, reads the endpoint URL from the AZURE_ML_MANAGED_ENDPOINT environment variable and the access key from AZURE_ML_KEY. Using the supported chat target means your red team work runs through the same objective target, conversation handling and memory that PyRIT uses for its other chat targets, rather than through a custom connector your team has to maintain.

Because the target is a chat target, it supports the same attack pattern as other PyRIT chat targets. You can run single-turn attacks that send one objective and score the reply, and multi-turn strategies in which PyRIT keeps the conversation history and adapts later prompts to earlier responses. Scorers evaluate each response, and PyRIT memory stores the prompts, responses and results so that a reviewer can trace a finding back to the exact exchange. Confirm with the PyRIT documentation for your release that the scorers and attack strategies you plan to use accept an AzureMLChatTarget as the objective target.

The target itself covers only the conversation with the endpoint. It does not provision the endpoint, set its scoring or guardrail configuration, manage its keys or network access, or decide which harms matter for your application. Those remain the job of your Azure Machine Learning platform team and your risk owners, and your red team plan should record who owns each one before testing starts.

What an Azure ML endpoint test needs before you start

Most delays in an Azure ML red teaming test come from setup gaps, not from PyRIT itself. The items below connect the endpoint, the test host and the people who approve the work, so the first attack run tests the model rather than the access path.

A deployed managed online endpoint

PyRIT's AzureMLChatTarget sends prompts to a managed online endpoint that is already deployed and serving the model you intend to test. Confirm that the endpoint is in the workspace you expect, that the deployment serving traffic is the model version under review, and that it responds to a simple prompt from a browser or client outside the test. A test against a stale or shadow deployment produces findings about the wrong model.

AML Chat Targets docs

Scoring URI and access key

The target needs the endpoint's scoring URI and an access key that the test identity is allowed to use. PyRIT defaults to the AZURE_ML_MANAGED_ENDPOINT and AZURE_ML_KEY environment variables, so these values are normally set in ~/.pyrit/.env rather than in notebooks. Confirm with your Azure ML workspace which authentication mode the endpoint uses and whether key-based access is permitted by your security policy before you copy any key.

A supported Python environment

PyRIT installs from PyPI and supports Python 3.10 up to but not including 3.15. The documentation recommends Python 3.13, so test hosts should be set up on that version or an approved version in the supported range. Check the environment on the same host that will run the attacks, including any virtual environment used by a CI job, because a mismatch often surfaces only when the first target is initialized.

Network reachability from the test host

The test host must reach the endpoint's scoring URI over the network path your organization permits. Managed online endpoints may sit behind private networking, so confirm whether the endpoint is public, reachable through a private endpoint, or limited to specific source addresses. Also confirm outbound access for any scorer or adversarial model the attack uses, since a test that works for the objective model can still fail when a scorer cannot connect.

Written authorization from the endpoint owner

Red teaming a deployed model generates high volumes of harmful-content prompts and may trigger content filters, alerts or cost controls. Get written approval from the owner of the endpoint and its workspace that names the endpoint, the test window, the test identity and the agreed scope. Keep this record with the test plan, because it is the first document an auditor or internal reviewer will ask for when reviewing results.

How to configure AzureMLChatTarget step by step

This sequence takes a team from a clean Python environment to a verified single-turn exchange with a model on an Azure Machine Learning managed online endpoint, with every credential kept out of source code.

  1. Install PyRIT from PyPI

    Create a dedicated virtual environment on a workstation or build host that your red team controls, then install the pyrit package 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 check your interpreter version before installing. Confirm the install by running python -c "import pyrit" without an error and by checking the installed version with pip. Record the version you tested, because later upgrades can change target behavior.

  2. Collect the endpoint URL and key

    In the Azure Machine Learning studio, open the managed online endpoint you plan to test and copy its scoring URI and one of its access keys. Confirm with the platform owner which deployment and key the red team is allowed to use, and whether the key is scoped to a non-production endpoint. Keep the values in your team's secret store until the next step. You are done when you can call the endpoint from a secure client with the same key and receive a response.

  3. Store the endpoint and key in the PyRIT env file

    Create or edit ~/.pyrit/.env and add AZURE_ML_MANAGED_ENDPOINT with the scoring URL and AZURE_ML_KEY with the access key. AzureMLChatTarget reads these two environment variables by default, so the notebook or script does not need to hold either value. Restrict the file to the operator account, for example with owner-only file permissions, and keep it out of version control. Check the setup by starting a fresh Python process and confirming that both variables load without printing their values into logs.

  4. Instantiate AzureMLChatTarget with defaults

    In a Python script or notebook, import AzureMLChatTarget from PyRIT and create it with no arguments so it uses the environment variables from the previous step. Where the endpoint needs explicit model parameters, such as temperature, maximum tokens or a message format your deployment expects, pass them as named arguments and write those values down in your test record. Reviewing the constructor signature in the PyRIT documentation for your installed version is the next read. You are done when the object constructs without an authentication error.

  5. Send one benign test prompt

    Send a harmless prompt such as a request for a short factual summary through the target, using the same prompt-sending call your team will reuse in attacks. The goal is to prove the connection, the key and the request format, not to test safety yet. Confirm that a text response returns and that the status is successful. If the call fails, check the endpoint URL, the key rotation status and whether the deployment is in a ready state before changing any code.

  6. Confirm the exchange is stored in memory

    After the test prompt returns, query PyRIT memory to find the conversation record for the exchange. PyRIT stores conversations and results in SQLite by default or in Azure SQL, so use the memory interface for your configured backend. Check that the record contains the prompt you sent, the endpoint's response, and the target identity. You are done when this record is visible, because every later finding and audit trail depends on it being captured from the first call.

Setting model parameters so test runs are repeatable

Fix the request parameters before the first attack runs, and write them down. The AzureMLChatTarget sends prompts to your managed online endpoint, so the sampling and length settings that shape each reply are set on the target, not in the model deployment you already own. Confirm which request parameters the target accepts in the AML Chat Targets documentation for the PyRIT version you have installed, because parameter names and defaults can differ between releases and between target classes. Check the supported list against what your endpoint's scoring script actually reads, since a parameter the target sends but the model server ignores will change nothing.

Temperature and the maximum output token limit change attack results between runs. A higher temperature produces more varied wording, so the same objective can succeed on one run and fail on the next, and a short token limit can cut off a harmful answer before a scorer sees it. Both effects make a success rate hard to compare across runs unless the values match. Treat a change to either setting as a new configuration, and rerun any baseline you intend to compare against. Where you want a result to be reproducible, agree the values with the team before testing begins and keep them constant across the objective, adversarial and scoring models where those are separate endpoints.

Record every parameter value with each run. Store the endpoint name, the deployment or model version, the temperature, the token limit and any other supported setting alongside the run's conversations, so a finding can be traced to the exact configuration that produced it. PyRIT memory keeps conversation history, but it will not tell an auditor which settings were in force unless you capture them yourself, for example in the scenario name, labels or a run manifest kept with your test records. When an endpoint is redeployed or its model is updated, record that change too, because the same parameter values can now produce different behavior.

How endpoint keys, roles and stored data map to PyRIT

PyRIT's AzureMLChatTarget reads the endpoint address and the endpoint key from the AZURE_ML_MANAGED_ENDPOINT and AZURE_ML_KEY environment variables by default. That means the key is available to any process that runs the test, and it typically ends up in a local environment file or a CI secret if nobody decides otherwise. Security engineers should decide where the key lives, who can read it and how it is rotated before the first run, not after.

  • Key location: Keep AZURE_ML_KEY in a managed secret store or a CI secret scoped to the test job, not in a shared file under ~/.pyrit/.env on a laptop.
  • Key holder: Name one owner for the endpoint key and record who can retrieve it from the workspace.
  • Rotation: Agree how the key is regenerated after a test cycle, and confirm that a rotation does not break scheduled runs.
  • Logging: Check that the run configuration and logs do not echo the key or the full endpoint header.
  • Scope of access: Confirm whether a key grants more than invoking the endpoint, and whether a narrower identity is available for testing.

Confirm these items in the Azure Machine Learning workspace: the authentication mode configured on the endpoint, the keys currently active, and the role assignments on the workspace and endpoint.

How a PyRIT attack reaches the Azure ML endpoint

The attack starts on the test host, where PyRIT loads the endpoint URL and key from ~/.pyrit/.env and builds prompts for the attack. AzureMLChatTarget sends each prompt to the Azure Machine Learning managed online endpoint, which crosses the trust boundary into the workspace. The model response returns to PyRIT memory, where the scorer reads it and records the result. Check that the endpoint and key variables point to the intended deployment, and that the host is the only place the key is stored.

Requests cross from the test host into the Azure ML workspace and return to PyRIT memory.

Using the endpoint in multi-turn attacks such as Crescendo

Multi-turn strategies such as Crescendo, TAP and Skeleton Key only work if the endpoint behaves as a chat model. These attacks keep a running conversation: each new prompt is sent with the earlier user and assistant messages, so the escalation builds on what the model already said. Before you rely on the endpoint for this, confirm that the deployed model accepts the chat message format that AzureMLChatTarget sends and returns a reply that PyRIT can parse. A model served with a custom scoring script or a non-chat input schema may accept a single prompt correctly and still fail once a second turn arrives. Check the input and response schema in your endpoint's deployment definition with the team that owns the model, and confirm the request format with the Azure Machine Learning documentation for your deployment type.

Run a short multi-turn dry run before you scale up. Use two or three turns against a harmless objective, then inspect PyRIT's memory to verify that each request carried the prior turns and that every reply was stored against the correct conversation. If the second turn reads as if the model has no context, the history is not reaching the endpoint, and a large run would waste compute and produce misleading results. Record the endpoint name, the model version, and the parameter values used for the dry run, so the result can be repeated later. Confirm the exact schema and any token or timeout limits with your Azure Machine Learning administrator, because these settings decide how long a Crescendo conversation can run before it fails.

Once the dry run passes, choose the attack strategy based on what you need to learn rather than on what is most familiar. The PyRIT attack strategies content group explains the cost and purpose of each multi-turn attack, and it is the right next read before you set the turn budget and scorer for the endpoint. Note that longer multi-turn runs make more calls to the endpoint, so the cost of the managed endpoint and the scoring model rises with the number of turns and objectives.

Hardening the endpoint key and the test environment

A managed online endpoint key gives full access to the model behind it, and PyRIT stores every prompt and response it sends. The cards below cover the controls that keep that key, the test host and the stored records appropriately protected, and the checks that keep testing authorized and off production traffic.

Scope and rotate the endpoint key

The AZURE_ML_KEY value authorizes calls to the endpoint, so anyone holding it can send traffic as your test harness. Use a key that belongs to the test deployment rather than a production one where your Azure ML setup allows it, and confirm which keys the endpoint issues and who can regenerate them. Set a rotation date after each red teaming cycle and rotate immediately if the key appears in logs, shared notebooks or chat threads. Confirm the rotation steps with your Azure ML administrators, since the exact controls depend on your tenant.

Keep secrets out of notebooks

PyRIT reads AZURE_ML_MANAGED_ENDPOINT and AZURE_ML_KEY from the environment, and it reads credentials from ~/.pyrit/.env. Keep those values in that file or in your secret store, and do not paste them into notebook cells, where they are saved with outputs. Add .env files and any exported notebooks to .gitignore, and scan commits for the key before pushing. Notebook output that echoes configuration should be cleared before sharing.

Restrict the test host

The machine that runs PyRIT holds the key and the memory database, so it should be a dedicated test host with a short list of users who can log in. Limit outbound network access to the endpoint's address and to the attacker and scorer models you use, and block other destinations where your network policy allows it. Record who can reach the host and where its Python environment and PyRIT memory files live. Ask your platform team which host baseline applies to security testing machines in your organization.

Govern prompt memory and retention

PyRIT memory stores conversations and results in SQLite or Azure SQL, and red teaming prompts often contain harmful or sensitive test content. Decide before the first run where the database lives, who can query it, and how long it is kept. Delete or archive memory after reports are issued, and avoid copying the database into shared folders. Confirm the retention rule with your data protection and legal teams, because the prompts themselves may fall under their policies.

Confirm authorization and rate limits

Before testing, get written approval that names the endpoint, the test window and the people allowed to run attacks. Set a request rate and concurrency that stays well below what the production application needs, and point PyRIT at a test deployment or a separate endpoint where possible. Watch endpoint metrics during the first runs and stop if latency or error rates rise for real users. Ask the endpoint owner how traffic is shared between test and production calls.

Why AzureMLChatTarget calls fail and how to fix them

This table lists the failures teams most often hit when AzureMLChatTarget sends prompts to a managed online endpoint, with the likely cause and the fix for each. Read it by matching the symptom you see in the run output to the row, then working through the fix in order. Most failures trace back to the two environment variables, the endpoint URL or the network path from the test host.

SymptomLikely causeFix
Target fails at construction or cannot find an endpointAZURE_ML_MANAGED_ENDPOINT is not set in the environment the run usesExport the variable in the shell, CI job or ~/.pyrit/.env that the run reads, then confirm it with a quick print before starting the attack
Authentication errors on the first requestAZURE_ML_KEY is missing, empty or copied with extra whitespaceSet the key from the endpoint's authentication settings in the Azure ML workspace, strip trailing newlines, and retry with a single prompt
404 or not-found responsesThe endpoint URL points at the wrong endpoint, deployment or pathCopy the scoring URL from the endpoint details page in the workspace and compare it character by character with the variable value
401 or 403 after a previously working runThe endpoint key was rotated or regeneratedRetrieve the current key in the workspace, update the variable everywhere the run reads it, and check that no cached environment still holds the old value
Connection timeouts or refused connectionsThe test host cannot reach the endpoint through firewall rules, private networking or proxy settingsTest reachability from the same host and network segment as PyRIT, then confirm outbound rules and any private endpoint configuration with your network team
Validation errors citing an unexpected parameterThe model's scoring interface does not accept one of the sampling or generation parameters PyRIT sentRemove or adjust the unsupported parameter in the target configuration, and confirm the accepted parameter names in the deployed model's documentation
Empty or truncated responses that scorers mark as errorsThe generation limit is too low, the model stops early, or the payload was cut off before the response was parsedRaise the maximum output setting for the target, inspect the raw response in memory, and confirm the scorer handles empty replies as a distinct outcome
Attacks stall or fail only in later turnsConversation history grows past the model's input limit, or the endpoint rate-limits repeated callsCheck the context length the deployed model supports, reduce history or turn count, and add retries or lower concurrency for the endpoint

Questions teams ask before testing Azure ML endpoints with PyRIT

What drives the cost or effort of testing an Azure ML endpoint with PyRIT?

Effort is driven mainly by how many endpoints and deployments are in scope, how much of the model's behavior you need to test, and how many multi-turn attacks you run. A single managed online endpoint with one chat-style model is a small job. Costs grow when you add separate deployments, different system prompts or tool-enabled configurations, and when each attack needs many turns. Model calls also cost money: the target endpoint, plus any separate adversarial or scoring model, bills per request on your own Azure subscription. Ask any partner to separate one-time setup work (environment, authorization, test design) from recurring work (reruns after model updates, reporting).

How long does a first working PyRIT setup against an Azure ML endpoint take?

The duration depends on what is already in place rather than on PyRIT itself. Installing PyRIT with pip is quick, and the documentation recommends Python 3.13 for the current release line. The time goes into getting the endpoint URL and key, confirming the request format the endpoint expects, deciding the objectives to test, and agreeing who may run attacks against it. If the endpoint already responds to a plain request from your test machine, a first run can happen within a short working session. If access, networking or key rotation has to be arranged first, expect that to set the schedule. Ask for a written plan that lists these prerequisites before committing to dates.

What must our internal team provide before an endpoint test starts?

Your team needs to provide four things before testing begins:

  • The endpoint: the managed online endpoint URL, and the deployment name if the endpoint hosts more than one.
  • A key with the least access that still lets the test run, passed to PyRIT through the AZURE_ML_KEY environment variable, never written into notebooks or shared scripts.
  • Written authorization: who approves testing, which hours are allowed, and whether production or only staging endpoints are in scope.
  • Scope: which harms and objectives matter for your use case, and which data or system prompts the model may see during tests.

Also confirm who receives the results and where PyRIT memory will be stored, since conversations may contain sensitive test content.

Can our team run PyRIT against Azure ML endpoints using only the documentation?

A developer who knows Python and has Azure ML access can get a basic AzureMLChatTarget connection working from the documentation, because the target reads AZURE_ML_MANAGED_ENDPOINT and AZURE_ML_KEY by default and accepts model parameters. The harder parts are outside the library: designing meaningful objectives, choosing scorers that match your harms, handling rate limits and failed requests, and interpreting results. Teams often find these design decisions take longer than the connection itself. If you have no one who can own those decisions, a fixed-scope engagement can cover them, and the written scope defines what your team keeps running afterward.

Can PyRIT results from an Azure ML endpoint serve as compliance evidence?

PyRIT produces records of prompts, responses and scores, which can support evidence for a compliance assessment, but the results do not make a system compliant on their own. Auditors and certification bodies decide what they accept, and DeployOpen does not issue audit reports, attestations or certifications. What helps most is a repeatable test procedure, a fixed scope, versioned objectives, retained memory records, and a clear link between each finding and the control or risk it addresses. Confirm with your assessor which frameworks and evidence formats they expect before the first run, and keep the endpoint version and configuration recorded with each test.

Does testing a live Azure ML endpoint carry operational risk?

Yes. Multi-turn attacks send many requests in sequence, which can raise latency, consume quota, trigger throttling or alerts on the endpoint, and in some cases affect other applications that share the deployment. Adversarial prompts can also produce harmful output that must be stored and handled carefully. Reduce the risk by testing a staging deployment where possible, setting concurrency and retry limits, agreeing a stop condition with the endpoint owner, and restricting who can read the PyRIT memory database. Confirm with your Azure administrators how the endpoint's quotas and monitoring are configured before testing.

How do we use an Azure ML endpoint in multi-turn attacks?

Pass the AzureMLChatTarget to a multi-turn attack such as Crescendo, which keeps the conversation history and sends each new turn in context. Each turn is a separate call to the endpoint, so the cost and duration of an attack scale with its turn count. Check that the endpoint's request format accepts the message history you send, and that model parameters such as temperature and maximum tokens are set deliberately so results can be compared across runs. Confirm how the specific model handles long conversations before setting turn limits.

What DeployOpen configures and verifies for your endpoint

DeployOpen's role on this work is to plan the test scope with your team, configure PyRIT and the AzureMLChatTarget against your managed online endpoint, run the attacks, and prepare the findings and memory records that your security and compliance teams can review. Scope comes first: which endpoints, which deployment slot, which harm categories and which attack types are in and out, and who may send traffic to the endpoint during testing. Those decisions are written down before any prompt is sent, because they determine what the results can and cannot support. DeployOpen then sets up the test environment so that the endpoint address and key are supplied through the AZURE_ML_MANAGED_ENDPOINT and AZURE_ML_KEY environment variables, or through the constructor arguments your team approves, and confirms that the target returns the responses the model is expected to produce.

Once the target answers reliably, DeployOpen runs single-turn attacks to establish a baseline for each objective, then multi-turn attacks where a model's behavior across a conversation matters more than its first reply. Model parameters such as temperature and maximum output tokens are recorded for each run, so a result can be reproduced later with the same settings. Scoring is configured to match the harms in scope, and scorer choices are documented alongside the results. Throughout, PyRIT's memory keeps the conversations and scores in SQLite or Azure SQL, and DeployOpen exports those records with the test configuration so that your team can trace each finding back to the exact prompt, response and score.

DeployOpen does not issue audit reports, attestations or certifications. The evidence it prepares is input for your internal reviewers and for any independent auditor or certification body you engage, and what those bodies accept is their decision. Before engaging, confirm with your compliance lead which evidence format they need, how long memory records must be retained, and whether the endpoint's own content filtering and logging are in scope. Ask any implementation partner to state in writing which of these items it will deliver, and which remain your responsibility.

How DeployOpen scopes, delivers and supports PyRIT endpoint testing

DeployOpen runs PyRIT red teaming against Azure Machine Learning endpoints as a written, fixed-scope engagement. We agree the endpoints, objectives, attack strategies and evidence in writing before any testing starts, then hand over the configuration and results so your own team can repeat them.

How we scope

  • Inventory the managed online endpoints, deployments and models in scope, and which ones accept the AZURE_ML_MANAGED_ENDPOINT and AZURE_ML_KEY configuration.
  • Agree the harm categories, objectives and multi-turn strategies to run against each endpoint, with the written scope fixing the boundary.
  • Confirm who owns the endpoint keys, where they are stored, and which scorer model and memory store will hold results.

How we build

  • Configure AzureMLChatTarget for each endpoint, with model parameters set to match the deployment and checked against a known-good prompt.
  • Wire the target into single-turn and multi-turn attacks, including Crescendo and other strategies agreed in scope, with scorers tuned to the use case.
  • Test in a non-production environment first, then run agreed attacks against the production-equivalent endpoint within the scoped window.

How we hand over

  • Deliver the PyRIT configuration, environment setup and run scripts, so your team can rerun the same attacks after changes.
  • Provide a findings report with reproduced conversations, scorer results, severity notes and suggested mitigations for each endpoint.
  • Document the memory records and evidence trail that a security or compliance reviewer would need to follow a finding back to its run.

How we support

  • Retest agreed findings after fixes are applied, and record the outcome against the original run.
  • Offer ongoing support, PyRIT upgrades and continuous testing as a retainer, with scope agreed in writing.
  • Ask for a quote based on the written scope, which sets the endpoints, attack set, retests and handover items included.

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.