Skip to content

Policy Templates and Policies

Policy models apply business rules to structured inputs and return a decision or calculation. AI Agent Studio can generate the function code during authoring. At runtime, the Policy node executes the published function, so the same inputs and policy version produce the same result.

Artifact When to use it
Policy template Define shared functions, inputs, return types, and generation guidance for a family of policies. For example, several return policies can use the same request input and decision output while applying different eligibility windows.
Policy Implement the rules for a specific policy and validate them with test cases. Select Generic for a standalone policy, or select a published policy template to reuse its function definitions.

Create a policy template

  1. In AI Agent Studio, open Policy Models → Policy Templates and select Add.
  2. In New Policy Template, enter Name. Studio populates Code. In Prompt, describe how to interpret source documents and what the generated functions must produce. Use Optimize to draft or refine the prompt.
  3. Under Functions, select Add Function. In Info, enter the function Name, Description, and Prompt. Describe the decision the function makes, the rules it must apply, and what it returns.
  4. In Input, select Add Parameter. Enter the parameter name, type, and description, then select Apply. Repeat for each input. Include units and valid values in the descriptions when the rules depend on them.
  5. In Output, set Return. For an Object return, define the output fields and types in JSON Spec. Apply changes where prompted. Repeat the function setup for each decision or calculation the template exposes.
  6. Select Publish. The published template becomes available in the Template list when you create a policy.

Create, test, and publish a policy

  1. In Policy Models → Policies, select Add. In Create Policy, enter Name and Description. Studio populates Code.
  2. Under Template, select Generic or a published policy template. Set Context if the policy should be scoped to a workflow. To assign a security role, select it under Security Roles → Role and select Add.
  3. For a Generic policy, enter generation guidance in Prompt. To generate functions from source documents, select Choose File to add the policy documents, then select Generate. To define an individual function in a Generic policy, select Add Function and provide the function requirements in the builder assistant.
  4. Under Functions, open each function. Review its metadata in Info, parameters in Input, return details in Output, and implementation in Source Code. Check that the implementation reflects the policy's precedence, thresholds, rounding, and handling of missing values.
  5. In Test Cases, use Mode to select Generate test cases or Upload a file. Check the expected results against the source policy, then select Run Test cases. Include cases immediately below, at, and above each threshold, as well as cases with missing inputs or competing rules.
  6. Select Save and Close to keep a draft or Publish to make the policy available to workflows. After a rule or template change, review and test the affected policy functions before publishing the new policy version.

To adapt a delivered model, open a seeded policy in Policies and select Customize. Review its source rules and test cases against your requirements before publishing the customized policy.

Use a policy in a workflow

  1. Add a Policy node after the workflow retrieves or validates the facts required for the decision.
  2. In Policy, select the published model. In Function, select the decision or calculation to run.
  3. Map the function's Parameters to the corresponding workflow inputs or upstream outputs. Configure the Error Handler if the workflow needs to handle evaluation failures separately.
  4. Use the function result in an If Condition, a Return node, or another downstream step. Test the mapped inputs and the result shape before publishing the workflow. See Policy node configuration.

Examples

Use case Policy inputs and decision How the workflow uses it
Purchase request review Evaluate the validated amount, currency, and purchase category. Return whether review is required and the reason. Send requests that require review to a Human Approval node before submission.
Invoice line validation Check quantity and amount against the invoice policy. Flag a line with a nonpositive quantity or a negative amount. Evaluate each extracted line in a For Loop and return the flagged line numbers. See Invoice Attachment Validation.
Product return eligibility Evaluate days since shipment, product category, and condition. Return eligibility and the next step. Reuse a template for product lines with different return windows. Route exceptions to a service representative.
Warranty coverage Compare the product's coverage dates and reported issue with the applicable warranty rules. Return the coverage decision and reason. Use the decision to route the service request or explain the outcome to the customer.

Purchase request review example

Define a Generic policy named Purchase Review Threshold. Specify a rule that requires review when a validated USD amount is at least 5,000. Validate the currency before calling the function. Define amountUsd as a numeric input and return an object with a Boolean requiresApproval field and a string reason field.

For an input of {"amountUsd": 5000}, the expected result is the following object.

{
  "requiresApproval": true,
  "reason": "The request meets the USD 5,000 review threshold."
}

Configure the Policy node with code CHECK_PURCHASE_POLICY and map amountUsd to the validated total returned by the purchase request lookup. In an If Condition, use {{$context.$nodes.CHECK_PURCHASE_POLICY.$output.requiresApproval == true}} to route the request to Human Approval. Treat missing amounts as validation failures before evaluation. Test 4,999, 5,000, and 5,001 USD to confirm that the threshold is inclusive.

See Approval Processes for the review routing that follows the policy decision.

Product return template example

Create a Return Eligibility template with an evaluateReturn function. Define daysSinceDelivery as a number and condition as a string. Set Return to Object and define a string decision and a string reason in JSON Spec. In the function prompt, specify the decision values ELIGIBLE, INELIGIBLE, and MANUAL_REVIEW. Use MANUAL_REVIEW when a required fact is missing.

Publish the template and create two policies from it. Upload each policy's source rules before generating the functions. For example, one product line could accept unopened returns within 30 days and another within 14 days. An unopened return submitted after 20 days is eligible under the first policy and ineligible under the second. Map both policies to the same downstream decision fields so the workflow can use the same routing logic for either product line.

See Evaluate return eligibility by product line for the workflow setup, sample requests, and exported policy files.