AI/LLM Security: Protecting a Production Document Pipeline from Prompt Injection and Data Leakage

A US company ran an LLM system that read freight invoices and checked them against contract rates. Devox Software mapped the pipeline’s attack surface, red-teamed it, and built layered defenses against prompt injection and data leakage.

AI/LLM Security: Protecting a Production Document Pipeline from Prompt Injection and Data Leakage

About the client

A US-based third-party logistics provider handles about 180,000 shipments monthly through a network of 3,000+ carriers

About the Product

The product is an LLM-powered document intelligence layer built into the client’s transportation management system (TMS). It reads bills of lading, proofs of delivery, carrier invoices and rate confirmations. It checks them against TMS records and contract rates, flags billing mismatches, and sends exceptions to operators. For instance, a retrieval layer over shipper contracts supplies the model with pricing context. Operators also use a chat assistant to ask questions about shipments and rates.

Introduction

At the first glance, the pipeline worked: it processed documents from the top carriers with 98%+ accuracy. However, the client’s CISO ordered a security review before an entire network rollout, and that review found a problem in security.

For instance, the model performed every instruction without a proof. That’s why the client asked Devox Software to find every way the AI pipeline could be manipulated or made to leak data, close those gaps, and prove the fixes worked, without rebuilding a system that already delivered value.

Project Team

  • 1 AI Solution Architect (fractional)
  • 1 Business Analyst
  • 1 ML/LLM Engineer
  • 1 Data Engineer (part-time)
  • 1 Full-Stack Engineer
  • 1 QA/MLOps Engineer (part-time)

Challenges

  • Untrusted input at scale. Many documents came from an outside party. A typical case would require approving an overbilled invoice or changing remittance details.
  • Cross-tenant data leakage. The retrieval layer indexed contracts for all shippers in a single vector store with no access filtering. A well-crafted query to the operator assistant could pull one shipper’s negotiated rates into an answer about another shipper.
  • Unprotected sensitive data. Observability tooling was from a third-party SaaS, so raw prompts with contract data were being stored outside the client’s Azure tenant which compromised compliance.
  • Excessive agency. The model’s output went straight into TMS status updates. One manipulated response could change a record with no deterministic check in between.
  • No adversarial test suite. Each prompt or model change could quietly reopen a closed hole, and the CISO needed evidence rather than assurances.

Tech Stack

  • AI / ML: Azure OpenAI (GPT-4o), Azure AI Document Intelligence, LangChain
  • AI security & guardrails: Azure AI Content Safety (Prompt Shields), custom injection classifiers, Microsoft Presidio (PII/PCI detection and redaction), JSON Schema output validation
  • Gateway & access control: Azure API Management (AI gateway), Microsoft Entra ID, RBAC, PostgreSQL + pgvector with row-level security
  • Infrastructure: Azure Private Link, Azure Key Vault, AKS, Terraform, GitHub Actions
  • Red teaming & evaluation: PyRIT, garak, custom adversarial test suite
  • Observability & audit: Langfuse (self-hosted in the client’s tenant), Azure Monitor, Microsoft Sentinel, immutable audit logging

Engagement Stages

1. AI Threat Modeling

We mapped every point where untrusted data entered the pipeline and then threat-modeled each one against the OWASP Top 10 for LLM Applications and MITRE ATLAS. This produced concrete threats along with a baseline of the current controls.

The client’s security team needed a defined scope they could defend to auditors. Mapping findings to recognized frameworks made each threat easy to verify, and ranking them told the team which ones to fix first.

2. Red Teaming

Before changing anything, we attacked the system as it was, using a row of adversarial scenarios. These included:

  • direct and indirect prompt injection
  • hidden text and instructions in PDF metadata
  • jailbreaks of the operator assistant
  • system prompt extraction
  • cross-shipper data retrieval
  • attempts to force invalid TMS updates

The baseline showed a 38% injection success rate and cross-tenant retrieval in 1 of 6 targeted queries. That gave the client a measurable starting point.

We combined open-source tooling (PyRIT, garak) with freight-specific scenarios built from real document formats, because generic jailbreak libraries don’t include a doctored bill of lading. Plus, patching the hidden-text exploit the client had already found and resuming the rollout would have been faster, but it fixed one known attack and left the rest of the attack surface untested.

3. Defense Implementation

No single filter stops prompt injection, so we layered the controls. Each layer covers what the others miss.

  • Input sanitization. Documents are normalized before the LLM sees them because this is the cheapest and most predictable place to stop an attack, before the content ever reaches the model.
  • Prompt isolation. Document content is passed as untrusted data, never as instructions because most indirect injections succeed because the model confuses data with instructions.
  • Injection detection. Azure Prompt Shields plus a custom classifier trained on freight-specific attack patterns screen every document and every assistant query to catch general injection techniques.
  • Data leakage prevention. Presidio redacts PII, bank details and rate data from prompts sent for tracing and from logs, so outputs are scanned before they reach the user. As Presidio runs inside the client’s cluster, sensitive data takes no extra trip to another service. We considered an alternative, a managed PII detection service but freight pricing fields would have needed a separate solution anyway, so we used one tool for both.
  • Constrained agency. LLM output must pass a strict schema and deterministic business rules before it can touch the TMS. High-value approvals and any change to payment details always go to a human.
  • Trust boundary enforcement. All model traffic goes through an Azure API Management AI gateway with Private Link. Tracing moved from SaaS to self-hosted Langfuse, so no prompt or response leaves the client’s tenant, because a single gateway gives one place to enforce policy, rate limits, key management and logging. The client’s shipper contracts required pricing data to stay inside its tenant, and redaction alone couldn’t guarantee that.

4. Continuous Security Validation

Any prompt, model or retrieval change that lowers the block rate fails the build. Injection attempts, blocked outputs and anomalous queries stream into Microsoft Sentinel with alerting because the client’s SOC already worked in Sentinel, so AI threats show up in the same queue as every other security event.

An immutable audit trail records every extraction, validation decision, guardrail trigger and operator override because billing disputes with carriers and compliance reviews need proof of exactly what the system decided and why. Standard application logs can’t provide that proof as they don’t link a decision to the guardrail events behind it.

There is an incident runbook and a quarterly red-team review process for the client’s security team. The client’s team needed to be able to respond and re-test without depending on Devox Software.

Results

  • Prompt injection success rate cut from 38% across adversarial scenarios
  • Near-zero cross-shipper data exposures in post-remediation testing
  • 100% of prompts and traces now stay inside the client’s Azure tenant
  • 99.2% of sensitive data redacted before logging
  • System prompt extraction blocked in all tested jailbreak variants
  • Accuracy kept at 95%+, with guardrails adding under 400 ms per document
  • Client security review passed, and rollout extended
  • Several real injection attempts in carrier documents were caught and blocked during the first 90 days in production

Sum Up

This project shows that the risk can be managed without giving up the business value. That takes threat modeling the whole pipeline, measuring exposure with real attacks, and layering defenses so no single control has to be perfect.

Book a call

Want to Achieve Your Goals? Book Your Call Now!

Having trouble booking? Open the booking page.

Contact Us

We Fix, Transform, and Skyrocket Your Software.

Tell us where your system needs help — we’ll show you how to move forward with clarity and speed. From architecture to launch — we’re your engineering partner.

Book your free consultation. We’ll help you move faster, and smarter.

Let's Discuss Your Project!

Share the details of your project – like scope or business challenges. Our team will carefully study them and then we’ll figure out the next move together.







    By sending this form I confirm that I have read and accept the Privacy Policy

    Thank You for Contacting Us!

    We appreciate you reaching out. Your message has been received, and a member of our team will get back to you within 24 hours.

    In the meantime, feel free to follow our social.


      Thank You for Subscribing!

      Welcome to the Devox Software community! We're excited to have you on board. You'll now receive the latest industry insights, company news, and exclusive updates straight to your inbox.