Converting only part of a prompt with PyRIT selective conversion

PyRIT can apply a converter to just the sensitive span of a prompt and leave the rest readable. This page explains how that works, when it finds weaknesses full encoding misses, and how to set it up and govern it.

On this page

Why teams test partial conversion with PyRIT selective conversion

PyRIT selective conversion converts only the sensitive part of a prompt and leaves the rest readable. A team red teaming a model or application often finds that its filters catch fully encoded prompts, because a Base64 or cipher-wrapped request looks unusual and gets blocked. Mixed content is a different question. A prompt that is mostly ordinary language with one encoded or obfuscated fragment may look closer to normal traffic, so the team needs to know whether its defenses inspect the whole input or only the parts that look suspicious. Testing only full encoding can give a false sense of coverage.

The PyRIT documentation describes selective conversion as an advanced technique for converting portions of prompts, within its converters material. It is not a separate attack family. It applies the converters your team already uses, such as encoding or obfuscation converters, to a chosen span of the text. Teams usually reach for it when a full-encoding run produces nothing useful, when a target answers an encoded prompt but refuses the plain one, or when they want to know whether a filter reacts to one token or to the overall request shape. Confirm the exact selection syntax and supported converters against the current converters page before you plan a run, since the documentation is the authority on how spans are specified.

Illustrative example: a team tests a support assistant that refuses a plain request about a restricted topic. A full-encoding run is blocked outright by an input check, which tells them little about the assistant's own judgment. A selective run that encodes only the restricted keyword, while the surrounding sentence stays in plain English, shows whether the input check and the model react differently. Either result is a finding worth recording, but only if the run is compared against a plain baseline and a full-encoding run with the same objective.

Before you start, decide what the test is meant to show. Record the objective, the converter, the span that was converted and the scorer used to judge responses. Keep the memory records so the comparison can be reproduced and reviewed later. Partial conversion widens the set of prompts you must generate and score, so ask the team who will own the results and how many variants they can review.

How a prompt flows through selective conversion to the target

The flow starts with an objective that PyRIT splits into a readable context segment and a sensitive segment. Only the sensitive segment passes through the converter, and the recombined prompt then crosses into the target, which is the trust boundary where the model or application under test receives input. The response returns to PyRIT scoring and memory, where the converted segment and the original objective should both be recorded so a reviewer can see exactly what was changed.

Only the sensitive segment is converted before the prompt reaches the target.

Why partial obfuscation often succeeds where full encoding fails

A mixed prompt can get past input checks that a fully encoded prompt trips. Many input filters are tuned to notice unusual text: long runs of Base64, heavy character substitution or a prompt that is mostly unreadable. When the entire request is transformed, the whole message looks anomalous, and the filter has an easy signal to act on. When only the sensitive phrase is converted, the surrounding sentence stays ordinary, so the request reads as normal language with one odd fragment. Whether that gap exists in your target depends on the filter, so treat it as a hypothesis to test rather than a property to assume. Selective conversion lets you vary how much of the prompt is transformed, which gives you a controlled way to find the point where a check starts to react.

A fully unreadable prompt can also fail to elicit a response, which means the test measures the wrong thing. A model that cannot decode the input cannot act on the request, so a refusal or an unrelated answer tells you little about whether the safety behavior holds for the content you care about. The result looks like a defense when it is really a comprehension failure. Partial conversion keeps enough of the instruction legible for the target to understand the task while still obscuring the element under test. Before you record any outcome, confirm that the target can recover the intent of the converted text. Run an unconverted baseline and a control variant that the target should answer, then compare results so a silent non-answer is not counted as a pass.

Validate the effect against your own target, with your own scoring. Model versions, system prompts, content filters and deployment wrappers all change how mixed text is handled, so results from one environment do not transfer to another. Record the exact converter settings, the proportion of the prompt converted and the target configuration for every run, so the comparison can be repeated after an upgrade. Ask your scoring approach to separate harmful output from confused output, and review a sample of responses by hand. Plan the test as a repeatable experiment with a stated hypothesis, not as a search for whichever variant happens to succeed.

Choosing how much of the prompt to convert

Converting a single keyword is the narrowest option. You apply the converter to one term that a filter is likely to match, such as a product name or a flagged verb, and leave the surrounding sentence in plain language. This tests whether the target's defenses rely on spotting specific tokens rather than understanding the intent of the whole request. Because only one word changes, the target usually still understands the request, which makes any refusal or compliance easier to attribute to the converted term.

  • What it tests: whether keyword or pattern-based filters catch a single disguised term while the rest of the request passes.
  • What it risks: very little readability loss, but a weak signal if the target ignores one odd word.
  • Confirm: that the converter you choose can be scoped to a word, and how it handles punctuation and spacing around that word in your PyRIT version.
  • Confirm: that the converted output is returned exactly as expected, since some converters change casing or add delimiters.
  • Record: the original term and the converted form in your run notes so the result can be reproduced.

Before relying on this option, check the converter's documentation in the PyRIT version you run, because word-level scoping is an advanced usage that may differ between releases.

Setting up selective conversion in a PyRIT test

This sequence takes a team from a supported Python install to a verified partial conversion, so each converted prompt can be traced to a baseline and a known span before any scaling happens.

  1. Confirm the Python version and install PyRIT

    The tester checks that the local interpreter falls in the range the PyPI package supports, which is Python 3.10 up to but not including 3.15, and the documentation recommends Python 3.13. They then install PyRIT from PyPI into an isolated virtual environment so the test run uses a pinned, known version. Done means the install completes and importing the package in a fresh Python session raises no errors. Record the exact PyRIT version, since converter behavior can change between releases.

  2. Configure the target and the scorer

    The tester sets credentials in the PyRIT environment file and settings in the configuration file, then defines the target model or endpoint the prompts will reach. A scorer is attached next, whether an LLM judge, Azure AI Content Safety or custom logic, so each response gets a recorded judgment. Confirm that the target returns a plain response to a harmless test message and that the scorer labels a known safe and a known unsafe example as expected. Both checks must pass before any attack prompt is sent.

  3. Write the objective with the sensitive span marked

    The tester writes the objective as a complete prompt and marks, in a clearly documented way, the exact words that carry the sensitive request. Surrounding words, such as the task framing and the output format, stay in plain text. The marked span should be short enough to convert in isolation and specific enough that the scorer can recognize a successful response. A short written note records why each span was chosen so reviewers can reproduce the selection later.

  4. Apply the converter to the marked span only

    The tester configures the selective conversion so the converter runs on the marked span and leaves the rest of the prompt untouched. The converter is chosen from PyRIT's converter catalog, and the chosen type is recorded with its settings. Check the output by printing the full converted prompt and confirming that only the marked words changed and that the unmarked text is byte-for-byte identical to the original. If any surrounding text changed, fix the selection logic before continuing.

  5. Run a baseline with unconverted text

    The tester sends the same objective with the marked span left as plain text and records the target's response and the scorer's label. This baseline shows whether the target already refuses the request without any transformation. Without it, a later success under conversion cannot be attributed to the conversion itself. The step is complete when the baseline result, including the scorer label, is stored in PyRIT memory with its run identifier.

  6. Check the converted prompt in memory

    Before scaling, the tester opens the stored conversation in PyRIT memory and reads the converted prompt exactly as the target received it. They confirm that the sent text matches the converted output from the earlier check, that the marked span is the only transformed part, and that the target's response is linked to that prompt. Reviewers should also confirm the scorer's label matches the response on reading. Only when the stored record shows the expected prompt, response and label should the run move on to additional objectives or attack variants.

  7. Scale only after the checks pass

    With the baseline and stored records verified, the tester expands the run to more objectives, keeping the same marking rules and converter settings so results stay comparable. Each new objective repeats the span check and a baseline, so a change in results can be traced to the prompt rather than to a configuration drift. Confirm the scaled run's records are complete in memory before reporting any success rate. Stop and recheck the configuration if any record is missing its baseline or its converted prompt.

Security and handling of test prompts

Selective conversion produces prompts that mix sensitive test content with readable text, and the converted prompts and responses are stored in PyRIT memory. The cards below cover where credentials and settings live, who can read stored results, and how to report a flaw in PyRIT itself.

Keep credentials in the environment file

PyRIT reads credentials from ~/.pyrit/.env, so API keys for the target and any scorer model stay out of scripts and version control. Confirm that the file is readable only by the account running the tests and that no team member copies it into a shared repository. Rotate keys when someone who had access leaves the testing group. Use the same pattern for every converter model you call, because LLM-based converters add another credential holder.

Store settings in the configuration file

Non-secret settings such as target endpoints, default converters and memory options belong in ~/.pyrit/.pyrit_conf. Keeping them in one reviewed file makes it clear which converter chain ran against which target when a partial-conversion result is challenged later. Ask whether your team needs one configuration per target system, so a selective-conversion run on a production-like endpoint cannot inherit settings meant for a test system.

Control access to memory

PyRIT memory stores the original prompts, the partially converted prompts and the target responses, and it can use SQLite or Azure SQL. Those records can contain sensitive test content, and the converted text may still expose harmful material even when most of the prompt is readable. Restrict file permissions on the SQLite database, or use Azure SQL role assignments and network controls, and confirm who may query, export or delete records. Define a retention rule before the first run.

Separate test data from production targets

Selective conversion is often aimed at filters and guardrails in front of a live system, so a misconfigured target can send test content to real users or logs. Before a run, confirm the target endpoint, the environment and the account that will call it. Keep test-only credentials distinct from production ones, and document which systems were in scope so the test results match what was actually exercised.

Report PyRIT vulnerabilities privately

If a test shows that PyRIT itself is vulnerable, for example a flaw in how it stores or transmits credentials, do not open a public issue. The project's security policy directs reports to the Microsoft Security Response Center, which allows the maintainers to assess and fix the problem first. Record the version you were running, the configuration involved and the steps to reproduce, and share them only through that private channel.

Selective conversion settings and when each fits

This table compares the four decisions a team makes when it converts only part of a prompt: the converter for the span, how the span is chosen, whether to run an unconverted baseline, and how results are labeled in memory. Read each row as a question to settle before the test plan is final, and confirm exact argument names in the PyRIT 1.1.0 converter documentation before coding.

DecisionWhat it changesWhen it fitsTrade-off
Converter type for the spanSets how the sensitive words are transformed, such as an encoding, a character substitution or an LLM rewriteEncoding fits filter bypass checks; LLM rewrites fit tests of paraphrase-based defencesNon-LLM converters are repeatable and cheap, but LLM rewrites add cost and run-to-run variation
Span selection by fixed keywordsConverts a named list of terms the team has chosen in advanceGood for a known blocklist or a specific sensitive term set in your own policyMisses synonyms and paraphrases, so coverage depends on how complete the list is
Span selection by position or structureConverts a chosen segment, such as the final sentence or a quoted blockUseful when the target often weighs instructions near the end of a promptResults can be hard to compare across prompts of different lengths and layouts
Running an unconverted baselineSends the same objective in plain text to the same targetAlmost always worth running, so the team can tell whether the partial change made a differenceDoubles the number of target calls for each objective
Single converter versus stacked convertersApplies one transformation to the span or chains several in orderSingle converters isolate which transformation changed the outcomeStacking can make the span unreadable to the target, which can cause refusals that do not reflect a defence
Labels recorded in memoryTags each attempt with converter, span rule, objective and baseline or variantNeeded for any run that will be compared, reported or reviewed laterLabels only help if they are set consistently; define the naming scheme before the first run
Scorer applied to each variantDecides whether the response counts as a success for that variantUse the same scorer for baseline and converted runs so the comparison is fairA scorer tuned for one converter may misread output from another
Exact argument names and syntaxDetermines how the converter and span settings are passed in codeAlways, before any test is writtenParameter names change between releases, so confirm them in the PyRIT 1.1.0 converter documentation

Limits to confirm before relying on partial conversion

Partial conversion looks simple in a notebook, but its results depend on details that change between PyRIT versions, Python versions, scorers and targets. The cards below list what to confirm in your own environment before you cite a result or build a test plan on it.

Converter support in your version

Confirm that the selective conversion technique is documented and supported in the PyRIT version you have installed, not only in the latest documentation. The PyRIT documentation describes selective conversion as an advanced technique for converting portions of prompts, but the exact converter classes, arguments and span selection behavior can differ across releases. Pin your version, run a small converter test, and record the output so a later upgrade can be checked against it. Confirm the exact converter API before you write any test code.

Converters docs

Python version behavior

The PyPI package supports Python 3.10 up to but not including 3.15, and the documentation recommends Python 3.13. Run your selective conversion tests on each Python version your team or CI pipeline uses, since string handling and dependency resolution can vary. A test that passes on one interpreter does not prove that the converted prompt is identical on another. Record the interpreter version alongside every test result.

Scorer treatment of partial text

A scorer reads the whole response, and a partially encoded prompt can produce a response that is only partly readable. An LLM judge, Azure AI Content Safety or custom logic may score the same answer differently depending on how much of it the target decoded. Before counting a bypass as a success, check how your chosen scorer handles mixed plain and encoded text, and manually review a sample of responses to confirm the scorer's verdicts.

PyRIT docs

Results depend on the target

Whether a partially converted prompt gets through depends on the model, its system prompt, its safety tuning and any input filter in front of it. A result against one deployment says little about another, even when the model name matches. Test against the exact deployed endpoint, configuration and content filter settings you intend to report on. Treat results from a different model or a local copy as a separate test.

Repository and maintenance status

The original Azure/PyRIT repository was archived on 27 March 2026 and is read-only. Development continues at microsoft/PyRIT, so point your dependencies, issue tracking and security reporting there. Check that your pipeline installs from the maintained source or the PyPI package, and that any fixes you rely on for converters are present in the version you run.

microsoft/PyRIT

Reproducibility of each run

Keep the seed prompt, the span selected for conversion, the converter settings, the target version and the scorer configuration with each run. Without these, a partial conversion result cannot be repeated or explained to an auditor or to the team that owns the model. Store the converted prompt as sent, not only the original, so reviewers can see exactly which words were encoded.

Questions teams ask about selective conversion effort and cost

What drives the effort of building a selective conversion test suite?

The main drivers are how many target systems you test, how many distinct sensitive spans you need to convert in each prompt, and how many converter combinations you run. Each target adds access work, authentication handling and response parsing. Each objective category adds seed prompts that must be reviewed for relevance. Scoring also adds effort, because you need a way to judge whether a partly obfuscated answer actually disclosed the protected content. Ask any provider to break its estimate down by these items so you can see which ones move the total.

How long does a first selective conversion run take?

The duration depends on scope rather than on a fixed number. A run against one chat endpoint with a small objective set takes far less work than a run covering several models, a web application and multiple languages. Setup, target integration, review of the first results and a rerun after fixes all add time. Ask for a timeline tied to a written list of targets, objective categories and deliverables, and check which phases are included, such as retesting after remediation.

Can an in-house team run selective conversion testing on its own?

Yes, if the team has Python skills, access to the systems under test and someone who can judge the results. PyRIT is open source under the MIT license, and it installs with pip on Python 3.10 up to but not including 3.15, with the documentation recommending Python 3.13. The harder parts are usually defining objectives that match your risk, writing scoring logic and interpreting partial-obfuscation results. Many teams start in-house for a pilot and bring in outside help for scope design or independent review.

What does the work need from our side?

Expect to provide test access to the target, a named technical contact, and written approval of the test objectives and the systems in scope. You will also need to confirm which data the tests may send to the model, where logs and PyRIT memory will be stored, and who signs off on findings. Target access often means test credentials, a staging environment or a rate limit agreement. Confirm these items before the work starts, because delays in access are a common source of schedule slip.

How should we ask for a quote from a written scope?

Ask for a quote that follows from a written scope listing the targets, the objective categories, the converters to be used, the scoring method, the deliverables and the retest terms. DeployOpen does not publish a price list, and most engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts. Compare quotes on the same scope, and ask which items are one-time work and which would recur, such as retesting after model updates or ongoing retainer testing.

Does selective conversion testing need approval from our security or legal team?

In most organizations, yes. Selective conversion sends deliberately sensitive prompts to a model, so the test plan should be reviewed by the owner of the system, the security team and, where personal or regulated data could appear, privacy or compliance staff. Confirm which prompt content is allowed, whether test output is retained in memory, and how findings will be handled. Written approval protects both the testing team and the business while the work runs.

What recurring costs should we plan for after the first run?

The first run is mostly one-time work. Recurring costs come from retesting after model, prompt or guardrail changes, from keeping objectives and seed prompts current, and from storing and reviewing results over time. Ongoing support, upgrades and continuous testing are available as retainers at DeployOpen. Ask any provider which parts of the test suite are reusable and what it costs to rerun them, so you can budget for each release cycle.

How DeployOpen scopes and supports PyRIT red teaming

DeployOpen is a Chainscore Labs company that delivers security testing, including AI and agent security testing, inside the infrastructure you control. For selective conversion work, that means the test harness, the target connections, the converter configuration and the memory store can run in your cloud account, data center or air-gapped network, so the prompts and responses that touch sensitive data never leave your environment. Before any work starts, the engagement needs a written scope that names the target system, the harm categories and the converter families in play, such as which converters are applied to which spans of a prompt, and which attack strategies are excluded. Ask whether the scope covers only the partial conversion technique or also the full-prompt baselines you will compare it against, because that choice changes the effort more than any other single decision.

Most engagements are fixed-scope. Scope, deliverables and timelines are agreed in writing before work begins, and DeployOpen does not publish a price list, so a quote follows from that written scope. The inputs that move the quote are the number of targets, how many converter variants and span-selection rules you want tested, whether multi-turn strategies are included, how much scorer tuning is needed to judge whether a converted prompt was actually answered, and whether the deliverable includes a retest after fixes. Ask for each of these as a separate line item so you can see which parts repeat if you rerun the test after a model or filter change. Confirm with the provider who supplies and maintains the target endpoints and any licensed scoring services, since those costs sit outside the testing fee.

Because selective conversion results shift when a model version, safety filter or system prompt changes, many organizations move from a one-time assessment to a retainer. A retainer covers recurring runs of the same converter and span tests, review of new findings, and updates to the harness when PyRIT changes its releases. Ask the provider how it handles PyRIT version upgrades in your environment, how it keeps the memory store and evidence exports consistent across runs, and what the retainer does not include, such as new target integrations or deeper research into a finding. DeployOpen does not claim partner status or certifications for PyRIT or any other tool, so confirm the tooling and support terms in the written agreement.

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.