Skip to main content
Use automatic rule extraction to turn a policy document into individual rules for review. The Python SDK starts extraction on the Vijil server, retrieves the resulting draft rules, and lets you use approved rules to structure a custom Harness. Before you start, install and authenticate the SDK. To create a Harness, you also need a registered Agent.

Prepare a Policy

Create a policy with the text you want to extract rules from:
You can also provide text through content, or pass file_path="policy.md" to read a local text file. The SDK sends that file’s text as source_text; this option does not upload or convert PDF files. To use an existing policy, including one you uploaded through the Console, retrieve it with policy = client.policies.show("<policy-id>"). It must contain the source text before you start extraction.

Extract and Retrieve Rules

Call extract_rules() with the policy ID, then fetch its rules:
extract_rules() returns a Policy, rather than the generated rules. By default, it waits for extraction and polls every five seconds. Set poll_interval to change that interval. Always check policy.rule_extraction.status before using the results. A failed or cancelled extraction returns the Policy with its status and optional error_message. If extraction status remains unavailable after repeated checks, the method also returns the Policy with rule_extraction=None; that does not confirm completion. Request failures, such as authentication or connection errors, still raise SDK exceptions. rules() returns a Page[PolicyRule]. Iterate page.items for the results and use page.total with limit and offset to retrieve more pages. The status filter accepts draft, approved, rejected, or modified; omit it to retrieve rules across review statuses.
Extract up to 50 rules from a policy. The limit argument on rules() controls how many existing rules you retrieve per page; it does not control extraction.

Check Status Without Waiting

Pass wait=False to start extracting draft rules from the policy text and return before extraction finishes. Extraction continues on the Vijil server. Retrieve the policy again when you want to check extraction progress:
Call show() to check an existing run. Calling extract_rules() again requests another extraction. The SDK does not set a deadline for extraction; use wait=False and your own polling deadline when your application needs one.

Review and Approve Rules

Extraction creates draft rules. Review their natural_language text and structured fields, such as rule_type, action, and consequence, against the original policy before approving them. The SDK currently has no dedicated rule approval method. Open the policy in the Console to review and approve the rules you want to use. After approval, retrieve them through the SDK:

Create a Harness From Approved Rules

Pass rule_policy_ids to include all approved rules from a policy:
Vijil automatically structures the Harness around the approved rules, with one dimension per rule, and generates test cases for each rule. You can use up to 50 rules in one Harness. Check Harness generation status before running an Evaluation. To select individual rules, pass rule_ids=["<rule-uuid>"] instead. Use each rule’s id UUID, rather than its human-readable rule_id. Only rules with approved status when you create the Harness contribute to generation. The Harness arguments serve different purposes: When you pass both rule_ids and rule_policy_ids, Vijil combines the rules and removes duplicates. Passing policy_ids alone does not select the policy’s approved rules.

Next Steps

Custom Harnesses

Check generation progress and manage your Harnesses.

Run Evaluations

Run an Evaluation with the generated Harness.
Last modified on November 10, 2026