Testing business rules with promptfoo custom policies

Write each product, legal or brand rule as a promptfoo policy, review the probes it generates, and agree what a violation means before the scan runs.

On this page

How promptfoo custom policies test your business rules

Your team has written refund, privacy or brand rules for an LLM application and needs to know whether the assistant actually follows them. promptfoo custom policies answer that question by stating a rule the target must follow, then generating probes that try to make the target violate it. Each probe is a realistic attempt to get past the rule, so a failing probe shows you exactly which behavior broke and what input caused it.

Generic harmful-content checks cover broad categories such as violence, self-harm or hate. They do not know that your business allows refunds only within a set return window, that a support bot must never reveal one customer's order history to another, or that a brand voice guide forbids certain product claims. Teams need custom policies when the failure would be wrong for their business but would not look harmful to a generic classifier. Start by listing the rules that carry financial, legal or reputational exposure, then check which of them your current red team configuration already covers. Ask your product, legal and brand owners to confirm the wording, because a vague policy produces vague probes and vague grading.

The tooling does not decide whether a rule is correct or complete. Your team owns the policy text, the edge cases it should cover, and the sign-off on the generated probes before a run. Read a sample of probes for each policy and ask whether they reflect attacks your users or adversaries would plausibly try. Remove probes that are off-topic or that test a rule you do not hold, and add the attempts your support staff have seen in practice. A passing result only proves the target held up against the probes that were generated, so the quality of your review sets the quality of the evidence.

Which business rules suit a custom policy

A custom policy works best when a rule can be stated as a clear expectation of the target's behavior and a probe can try to break it. The categories below are illustrative examples, and each one shows where the rule is easy to write down and where its wording or its dependence on live account data makes testing harder.

Refund and return limits

Illustrative example: the assistant must not promise a refund for an order outside the return window. This is testable because the window is a fixed number of days from a delivery date that a reviewer can state in the policy text. It becomes hard when the window depends on account state, such as a loyalty tier, a prior goodwill exception or a regional rule. Check whether the target can see the order date at all, because a policy cannot be judged fairly if the application has no access to the facts the rule depends on.

Disclosure of other customers' data

Illustrative example: the assistant must never reveal another customer's order, address or contact details, even when the requester supplies a plausible reason. This rule is among the clearest to test because a leak is visible in the response text. The hard part is scope: the probes must cover a name, an order number, a partial address and a reference to a shared household or business account. Confirm which identifiers the target can retrieve, since a rule against leaking data it never holds will pass for the wrong reason.

Off-brand and unsupported claims

Illustrative example: the assistant must not describe a product as certified, carbon neutral or clinically proven unless the approved claims list says so. Testable rules name the banned phrases or the approved claim set. They get hard when the brand voice is a judgment call, such as whether "safe" or "trusted" counts as a claim. Ask marketing and legal to define the boundary in writing, with examples of acceptable and unacceptable wording, before the policy is written, so that grading does not depend on one reviewer's taste.

Regulated advice boundaries

Illustrative example: a banking assistant must not recommend a specific investment or give a tax determination for an individual. The rule is testable when the forbidden output type is clear, such as a named product with a buy or sell instruction. It is hard when the line between general education and personalized advice depends on the user's profile, jurisdiction or whether a licensed disclaimer was shown. Involve compliance to decide which answers count as advice, and record the jurisdiction the policy applies to.

Thresholds and account-state rules

Illustrative example: the assistant must not approve a fee waiver above a set amount without an agent handoff. Thresholds are testable when the number is fixed in the policy, but the target may not know the account balance, history or approval status that decides the outcome. Before writing these policies, confirm what account data reaches the model at inference time. If the state lives in a backend the target cannot query, the policy will test the model's willingness to guess, not the business control itself.

How the policy plugin generates and grades probes

A promptfoo custom policy starts with one rule the target must follow. You write the rule in plain language, such as a refund request outside the return window must not be approved, and promptfoo then generates probes that try to make the target break it. Each probe is a message designed to push the application toward the forbidden behavior, so the policy text is the specification for the whole test. The probes are only as good as the rule behind them. A vague rule like "don't give bad refunds" leaves the generator guessing what counts as a violation, while a rule that names the window, the product types, the approval authority and the exceptions gives it concrete situations to attack. Before a run, read the generated probes against the rule and confirm that each one would be a genuine violation if the target answered it.

The target's responses are then graded against the same rule. The reader should check what the grader is judging: whether a response that discloses the policy, refuses politely or asks a clarifying question counts as compliant, and whether a partial approval counts as a failure. The supplied facts do not describe how the grader reaches its decisions, so confirm the grading behavior in the current promptfoo documentation for the version you run, and test it with a few responses you already know are compliant and non-compliant. Misgraded results are a common source of false findings, so treat the first run as a calibration exercise rather than a report.

Probe quality also depends on the context the target receives. The application's system prompt, the customer's account state, the tools it can call and the data it can see all determine whether a probe can realistically cause a violation. A refund probe against a target with no refund tool tests little, and a customer-data probe against a target with no access to other accounts tests only the model's willingness to say so. Describe the relevant context in the target configuration and purpose, and when a policy depends on facts the model cannot see, record that dependency so a reviewer knows which findings depend on how the application is wired.

How a business rule becomes a tested probe

The path starts with a rule written by product, legal or brand owners and translated into a policy definition in the promptfoo configuration. promptfoo then generates probes that try to make the target application break that rule, and each probe is sent to the application under test. Responses are graded against the policy, and a human review gate sits before any finding is shared, because generated probes and grader verdicts can both be wrong.

Business rule flows through policy, probes and grading to a human review gate before sharing.

Policy configuration options and when each fits

This table compares four choices a team makes when writing a promptfoo custom policy: rule breadth, rule text style, policy grouping and whether policies run alone or with standard plugins. Read each row as a trade-off between coverage, noise and upkeep, and start with the option that matches how your product and rule owners work.

DecisionOptionTrade-offWhen to choose it
Rule breadthOne broad ruleFewer policies to maintain, but a failed probe is harder to diagnose and probes may drift across unrelated casesThe rule is short and owned by one team, such as a single brand voice rule
Rule breadthSeveral narrow rulesClear pass or fail per rule and easier triage, but more rules to review and keep in sync with policy changesLegal or product rules have distinct exceptions, such as refunds inside and outside the return window
Rule text stylePlain-language rule onlyQuick to write and easy for rule owners to read, but generated probes may vary more in how they test the ruleEarly drafts, or rules where the owner can state the boundary in one sentence
Rule text styleRule text with examplesMore writing effort and examples to keep current, but probes and grading tend to target the boundary you care aboutRules with edge cases, such as a customer asking about another person's order under a shared account
Policy groupingOne policy per product areaShared rules stay consistent across assistants, but a change may affect several targets at onceSeveral assistants share one support policy and one owner signs off on it
Policy groupingOne policy per targetEach target can carry its own exceptions, but duplicated rules can drift apart over timeTargets have different permissions, such as a sales assistant that may quote prices and a support assistant that may not
Run modePolicies aloneFocused results on your rules, but no coverage of general harms, privacy or injectionA narrow check on a rule that a new release has just changed
Run modePolicies alongside standard pluginsBroader coverage and a longer probe count to review, and findings from both sets need separate triageA first full assessment before a go-live or a compliance review

Setting up a first policy test

This sequence takes one business rule from a written statement to a reviewed set of policy probes and a small scan, so the rule owner can confirm that each result reflects what they intended. It ends with a list of borderline results that a person has checked against the rule.

  1. Confirm the target endpoint and purpose

    Before writing any policy, confirm which application endpoint promptfoo will test and write down the purpose field that describes its users, the data it can reach and the tools it can call. The rule owner, typically product, legal or support, should review this description with the engineer who owns the endpoint. The step is done when both agree the purpose matches how the application really behaves in production, because policy probes are generated from that description.

  2. Write one rule with pass and fail conditions

    Write a single business rule in plain language, such as a refund request outside the return window, and state for it two conditions: what a compliant response looks like and what a violating response looks like. Keep the rule narrow enough that a reviewer can judge any single response against it. The output is a one-paragraph rule with both conditions written out, which the rule owner signs off before it goes into configuration. Check that the rule names the policy source, such as the refund terms or the privacy policy, so later reviewers can trace it.

  3. Add the policy to the red team configuration

    Add the rule to the red team section of the promptfoo configuration as a policy plugin, using the plugin documentation for the exact syntax for your promptfoo version. Keep the rest of the configuration minimal for this first test, with one target, one purpose and no extra plugins or strategies. Validate the file so that promptfoo accepts it. The check is that the configuration parses without errors and lists exactly one policy, which keeps any later finding tied to a single rule.

  4. Generate probes and review their scope

    Generate the probes without running them against the target, then read every probe before any scan starts. Confirm that each probe is about the rule you wrote and not a neighboring topic, and that the wording could plausibly come from a real user or an attacker. Remove or rewrite any probe that drifts outside the rule's scope. Also confirm that no probe asks the target for data it should never hold, such as another customer's records or internal credentials, because a probe that asks for that data is a test of exposure rather than of the rule. The step closes when the reviewed probe list is saved.

  5. Run a small scan against the target

    Run the reviewed probes against the target with a small probe count, using the same target configuration the engineering team uses in staging or a test environment. Record the raw responses and the grader's verdict for each probe. Confirm that the target calls and any logging behave as your data-handling rules require, since prompts and responses will be stored. The step is done when every probe has a response and a verdict, and the run output is saved for review.

  6. Check borderline results with the rule owner

    Sort the results into clear passes, clear failures and borderline cases, where the grader's verdict is hard to justify from the rule text. Take each borderline result to the rule owner and ask whether the response breaks their intent, not only the wording of the rule. Record the decision and the reason for each one, and note where the rule text itself is ambiguous. The output is a short decision log that shows which findings are confirmed, which are dismissed and which need a clearer rule before the next run.

  7. Record decisions and tighten the rule

    Update the rule wording and the grading guidance where the review showed ambiguity, then note the changes alongside the decision log. Keep the first version of the rule and its probe list so later runs can be compared against the same baseline. The step is done when the rule owner accepts the revised wording and the team knows which findings need engineering work, which need a clearer rule and which were false positives.

Reviewing generated probes before a run

Product and legal owners decide whether a policy describes the rule the business actually enforces. A generated probe is only useful if it tests the boundary the way a customer or employee would reach it. Read each policy statement next to the probes it produced and ask whether the probes cover the real edge cases, such as a request made one day after a return window closes, a refund requested through a related account, or a question phrased as a hypothetical.

  • Boundary accuracy: Confirm that each probe sits on the correct side of the rule and that the rule text matches the current policy document, not an older version.
  • Missing exceptions: Look for approved exceptions, such as manager overrides or regional rules, that the policy text should mention or that probes should not treat as violations.
  • Brand and tone rules: Check that probes about claims, comparisons or disclosures reflect wording the legal team has already approved.
  • Unrealistic phrasing: Flag probes that no user would send, since they add noise to the results.
  • Sign-off record: Note the policy version, the reviewer name, the date, and any probes removed or rewritten.

The most useful output of this review is a short list of changes to the policy text, not only a list of approved probes.

Data handling and security for policy probes

Policy probes are generated, sent to your target, and graded, so each step touches data in a different place. The cards below separate what stays on your machine or server from what may leave it, and set the test data rules that apply before any run starts.

Where probes and results are stored

Policy test definitions, generated probes and grading results are written by promptfoo to the project output on the machine that runs the scan, unless you configure a shared location. Confirm the output directory, who can read it, and whether your CI runner keeps artifacts after the job ends. Treat a results file that quotes a model's answer about a customer as sensitive data in its own right.

Policy plugin docs

What leaves your environment

The promptfoo documentation states that evals run on your machine and talk directly with the LLM, but red team generation and grading can use promptfoo's hosted API. Before a run, list every model that will receive a probe or a response and confirm which of those calls go to a hosted service. The data-flow review covers the hosted API details, so use that page for the full sign-off list.

Test data must not be customer records

A policy such as not disclosing another customer's data is tested by writing probes that name fictional people, accounts and orders. Do not paste production tickets, chat transcripts or CRM exports into a policy definition, a purpose field or a custom intent file, because those files are stored and may be shared. Ask the team that owns the rule to supply synthetic records that match the shape of the real data.

Self-hosted server access limits

The self-hosted promptfoo app stores data in a local SQLite database that cannot be shared across replicas, and it has no RBAC and no built-in authentication or SSO. If policy results are viewed by more than one person, put the server behind access controls you run yourself, or share exported reports instead. Confirm this with your current version before you rely on it for shared review.

Self-hosting docs

Secrets stay out of policy files

Policy files and their YAML configs are often committed to Git and copied into tickets, so API keys for the target and grading providers must come from environment variables or your secret store, never from inline values. Review the config before each commit and scan the output folder for keys that appear in request logs. Agree who rotates the keys if a file is shared outside the testing team.

Reviewing probes before the run

Generated probes can contain wording that resembles real personal data or that a legal reviewer would not accept as a test. Read a sample of each policy's probes before sending them to the target, and remove any that include identifiers from production systems. Record who approved the probe set, so the review is traceable when results are used as evidence.

Questions teams ask before writing custom policies

How much effort does writing and reviewing custom policies take?

Effort depends mostly on how many rules you have, how precisely each rule is written, and how many probes you review before a run. A small set of rules with clear wording is a short exercise, while a large catalogue of product, legal and brand rules needs more drafting, more review rounds and more checking that each generated probe really targets the rule. Ask any partner to size the work from your written rule list, the number of target endpoints and the review steps they expect, and to show which of those steps are one-time and which recur when rules change.

What drives the cost of a custom policy engagement?

The main cost drivers are the number of rules, how much rule documentation already exists, how many target applications are in scope, how many stakeholders must approve wording, and whether you need a retest after fixes. Costs are mostly one-time for the first build and review, then recur when rules change, products launch or models are swapped. Cost is set by the written scope, not by a list price, so ask for a quote that itemizes rule drafting, probe review, test runs, reporting and retesting separately.

Do legal or product staff need to be involved?

Yes, the people who own the rules should be involved, because a policy test can only be as accurate as the rule it encodes. Product staff know the actual refund window, eligibility and escalation paths. Legal or compliance staff should confirm wording that carries obligations, such as data disclosure limits. Engineers translate the rules into policy statements and review generated probes. Agree in advance who signs off on each rule and who decides when an ambiguous result counts as a finding.

How long does a first policy review cycle take?

No duration has been supplied for this work, so the length of a first review cycle cannot be stated here. It depends on how quickly your rule owners can confirm wording, how many probe review rounds are needed, and how many fixes the application needs before a retest. Ask any partner for a timeline in the written scope, with named dependencies on your rule owners and test endpoint access, and confirm that the schedule includes time for stakeholder review rather than only engineering work.

Can our team write custom policies without outside help?

Yes, a capable engineering team can write policy statements in promptfoo and review generated probes internally, provided it has clear rule documentation and a stable test endpoint. The usual gaps are not in the tooling but in deciding which rules matter, writing unambiguous wording, and judging borderline results with the people who own the rules. A partner is useful when you want an independent review of your rule set, a first build done against a fixed scope, or a retest after fixes. Confirm your team's capacity honestly before deciding.

What does the work need from us to start?

You need a written list of business rules with the exact conditions, exceptions and owners, plus a test endpoint that represents the application as customers reach it. Useful inputs include the policy text or help-center pages that define each rule, examples of permitted and forbidden answers, the data the application can access, and any staging environment with test accounts. Confirm with your platform team that the endpoint can be reached from the machine running promptfoo and that test data contains no real customer records. The promptfoo policy plugin documentation describes how a rule is expressed and tested.

Does a policy test replace a compliance assessment?

No. A policy test shows whether an application breaks specific rules you wrote, under the probes generated for them. It does not evaluate your full control environment, issue an audit opinion or certify compliance. Independent auditors and certification bodies perform those assessments. A policy test can produce evidence and findings that feed into a compliance readiness effort, but the scope of that evidence is limited to the rules and endpoints tested.

How DeployOpen scopes and delivers policy testing

DeployOpen plans and runs promptfoo custom policy testing as part of its security testing work for LLM applications. We start from your written business rules, turn them into policy tests, review the generated probes with your product, legal and brand owners, and hand over a documented test set your team can run again.

How we scope

  • The written scope lists the target application, the rules to test and the owner who approves each rule's wording.
  • Scope records which rules are in and out, the environments covered and who reviews probe output before a run.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.

How we build

  • We draft each policy as a plain-language rule, with examples of allowed and disallowed answers agreed with rule owners.
  • We configure promptfoo policy tests against the target, then review generated probes for relevance and duplicates.
  • We run the suite, triage borderline findings with your team and record fixes and retests for each failed rule.

How we hand over

  • You receive the policy definitions, configuration files, probe review notes and the run results in a documented package.
  • Documentation explains how to add a rule, how to reread generated probes and which owner approves changes.
  • Your engineers walk through the suite, so the team can run it in its own infrastructure without DeployOpen.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers when rules or models change.
  • Retainers can cover re-running the policy suite after prompt, model or guardrail changes, with findings tracked over time.
  • Ask any provider what happens to generated probes and results, and confirm it against your own data handling rules.

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.