Local LLM Red Teaming with PyRIT & LM Studio
Adapting Microsoft PyRIT orchestrators to local OpenAI-compatible endpoints and CSV audit logs.
Microsoft’s PyRIT (Python Risk Identification Toolkit) is built primarily around Azure OpenAI cloud endpoints. This experiment documents adapting PyRIT to attack local open-weight models served by LM Studio, benchmarking five obfuscation converters, and resolving API and scoring failures.
1. Local Endpoint Stabilization
Section titled “1. Local Endpoint Stabilization”By default, OpenAIChatTarget injects Azure-specific parameters that cause errors or unexpected rejections on local OpenAI-compatible servers. Explicitly stripping api_version=None stabilized requests against LM Studio.
import asynciofrom dotenv import load_dotenvfrom pyrit.common import initialize_pyrit, IN_MEMORYfrom pyrit.orchestrator import PromptSendingOrchestratorfrom pyrit.prompt_target import OpenAIChatTarget
load_dotenv()initialize_pyrit(memory_db_type=IN_MEMORY)
async def check_connection(): local_target = OpenAIChatTarget(api_version=None) orchestrator = PromptSendingOrchestrator(prompt_target=local_target) responses = await orchestrator.send_prompts_async( prompt_list=["Confirm receipt of this connectivity test."] ) print(responses[0].request_pieces)2. Obfuscation Converter Benchmark
Section titled “2. Obfuscation Converter Benchmark”Using slices from fetch_adv_bench_dataset(), five transformation chains were evaluated:
- Baseline (no conversion)
Base64ConverterROT13ConverterUnicodeConfusableConverterAsciiArtConverter- Chained two-layer conversion:
[LeetspeakConverter(), UnicodeConfusableConverter()]
3. Observed Failure Modes on Local Models
Section titled “3. Observed Failure Modes on Local Models”- LLM-dependent converters (
TranslationConverter): Unreliable when backed by smaller local models; deterministic transforms (LeetspeakConverter,UnicodeConfusableConverter,Base64Converter) remained predictable. - Automated LLM scorers: Built-in PyRIT scorers misfired frequently against small local weights, requiring a fallback to deterministic indicator matching and manual review.
4. Reproducible CSV Audit Trail
Section titled “4. Reproducible CSV Audit Trail”Every benchmark run exported timestamped rows (Timestamp, Objective, Resultado, Prompt Convertido, Respuesta del Modelo) to per-model CSV files so model comparisons stayed verifiable outside terminal scrollback.