Articles

How Prompt Injection Can Make a Risky Contract Look Safe

3 min read

Web Format

Esha Pahwa | Machine Learning Engineer at Ruli

Esha Pahwa | Machine Learning Engineer at Ruli

Protecting Legal AI from Prompt Injection — Keeping Legal Reviews Aligned with Client Instructions. Ruli Engineering.

How Ruli Tests and Strengthens Safeguards for AI Contract Review

Imagine an AI review comes back clean even though the counterparty’s draft exposes your company to unlimited liability. The draft contains language that tries to keep the issue out of the review. That attempt to turn document text into instructions for the AI is called prompt injection.

At Ruli, we tested whether a counterparty’s draft could change what the AI flagged, influence an approval recommendation, or cause the AI to reveal protected review instructions.

Figure 1: A directive to suppress a liability finding could leave counsel unaware of an exposure outside the client’s playbook.

Figure 1: A directive to suppress a liability finding could leave counsel unaware of an exposure outside the client’s playbook.

Keeping Client Instructions in Control

In a contract review, the agreement supplies the terms to analyze. The client’s request and playbook establish whose interests to assess, which risks to flag, and when to escalate. Ruli’s safeguards are designed to preserve those instructions throughout the review.

How Prompt Injection Can Compromise a Legal Review

Table 1: Prompt injection risks and expected safeguards.

Table 1: Prompt injection risks and expected safeguards.

Figure 2: A forged system notice attempts to expose confidential review instructions by claiming authority it does not have.

Figure 2: A forged system notice attempts to expose confidential review instructions by claiming authority it does not have.

When a Buried Instruction Becomes a Missed Risk

Figure 3: A directive to approve a 180-day payment term could hide a cash-flow concern the client asked counsel to identify.

Figure 3: A directive to approve a 180-day payment term could hide a cash-flow concern the client asked counsel to identify.

A finding like this gives in-house counsel a reason to involve Finance or propose a redline. If the review recommends approval and leaves out the exception, the agreement could move toward signature before either happens.

Inside Ruli’s Evaluation and Mitigation Process

We used an open-source AI security platform called Promptfoo to run synthetic agreements containing adversarial document text through the application’s review prompts and model. This gave us realistic contract language without using customer documents. Automated checks graded whether the AI completed the requested review, surfaced required findings, and kept protected instructions confidential. In a scenario like Figure 1, a passing response would still flag the liability exposure the playbook calls out.

We strengthened the instruction hierarchy by making the authorized task explicit and keeping agreement text separate from the instructions that govern the review. Then we reran the same cases with the same grading criteria. We kept the inputs, responses, and tested versions so we could reproduce the comparison and see how the review behaved before and after the change.

Putting Guardrails into Practice

Table 2: A practical framework for testing and mitigating prompt injection.

Table 2: A practical framework for testing and mitigating prompt injection.

Once you’ve defined what a review needs to do, you can test for it as you build the tool and each time you update it.

For Engineering Teams

Before releasing a prompt update, rerun the prompt injection and legal accuracy tests. Keep each prompt version with its test cases and grading criteria so you can investigate any regressions. At Ruli, we have a CI/CD check and evaluate pipeline that would rerun a focused set of tests after prompt changes are merged.

For In-House Legal Teams Building Their Own AI Tools

Start with one workflow, such as screening vendor agreements against your company’s contract playbook. Decide which terms the tool must flag and when it should escalate to Legal. Use synthetic agreements in development and limit access to sensitive information. Always have an in-house lawyer review AI-generated responses before anyone relies on them or shares them.

Legal can define the findings counsel needs to see, and Engineering can test whether the review still reports them during a prompt injection attempt. Together, they can check whether the analysis reflects the agreement accurately enough for counsel to act.

Stop reacting. Start monitoring

See how Ruli Monitor keeps your team one step ahead of the regulations that matter most.

Stop reacting. Start monitoring

See how Ruli Monitor keeps your team one step ahead of the regulations that matter most.

Stop reacting. Start monitoring

See how Ruli Monitor keeps your team one step ahead of the regulations that matter most.