The /rules/ai/* endpoints turn natural-language requests into rule YAML and JSON. The same service explains existing rules in plain English and refines a rule based on feedback.
Generate from English
/rules/ai/generateJWTcurl -X POST https://appengine.appmint.io/rules/ai/generate \
-H "x-org-id: $ORG" -H "x-customer: $USER" \
-H "Content-Type: application/json" \
-d '{
"englishDescription": "Apply a 10% discount when the order has 5 or more lines and the customer is in the gold tier.",
"context": {
"availableFields": ["order.lineCount", "order.total", "customer.tier", "customer.country"],
"businessDomain": "ecommerce"
}
}'
| Field | Type | Description |
|---|---|---|
| englishDescription* | string | The plain-English ask. Specify the trigger condition, the action, and any thresholds. |
| context.availableFields | string[] | Field paths the AI may reference. Constrains the generator to real schema. |
| context.businessDomain | string | Domain hint ( |
| context.organizationTerms | object | Map of org-specific terminology to canonical names. |
| provider | string | LLM provider override. Defaults to the org's configured AI provider. |
Response:
{
"success": true,
"generatedRule": {
"id": "GOLD_BULK_10",
"yaml": "version: 2.0\nrules:\n - id: GOLD_BULK_10\n when: order.lineCount >= 5 AND customer.tier == 'gold'\n then:\n apply_discount:\n type: percent\n value: 10\n",
"json": { "id": "GOLD_BULK_10", "when": { "and": [{">=":["order.lineCount",5]},{"==":["customer.tier","gold"]}] }, "then": { "apply_discount": { "type": "percent", "value": 10 } } }
},
"confidence": 0.95,
"explanation": "Triggers when at least 5 lines AND customer is gold-tier.",
"suggestions": [
"Consider adding an else branch to apply 0% otherwise."
]
}
The rule is not saved. Inspect the YAML, then approve.
Approve and save
/rules/ai/approveJWTSaves the generated rule as a new rule set:
curl -X POST https://appengine.appmint.io/rules/ai/approve \
-H "x-org-id: $ORG" -H "x-customer: $USER" \
-d '{
"generatedRule": { "id": "GOLD_BULK_10", "yaml": "...", "json": { ... } },
"ruleSetName": "Gold-tier bulk discount",
"description": "10% off for gold customers with 5+ lines",
"active": true
}'
Refine with feedback
/rules/ai/refineJWTIterate on a rule without rewriting it:
curl -X POST https://appengine.appmint.io/rules/ai/refine \
-H "x-org-id: $ORG" -H "x-customer: $USER" \
-d '{
"originalRule": { /* existing rule JSON */ },
"feedback": "Increase the discount to 15% and require minimum order total of $500."
}'
Returns the same shape as generate.
Explain a rule
/rules/ai/explainJWTConvert a rule back to plain English. Useful in admin UIs where business users need to understand a rule without reading YAML.
curl -X POST https://appengine.appmint.io/rules/ai/explain \
-H "x-org-id: $ORG" -H "x-customer: $USER" \
-d '{"rule": { /* rule JSON */ }}'
Test a generated rule
/rules/ai/testJWTRun the rule against sample data and compare to the expected outcome.
{
"rule": { /* generated */ },
"testData": { "order": { "lineCount": 6 }, "customer": { "tier": "gold" } },
"expectedOutcome": "10% discount applied"
}
Limitations
- Schema discipline matters. Always pass
availableFields— the generator tends to invent fields likeorder.itemCountwhen the real path isorder.lineCount. - Confidence under 0.7 signals an ambiguous request. Re-prompt with more detail.
- Helper functions must already be registered. The AI won't invent custom helpers, but it may use a built-in (
SUM,FILTER) that you need to verify against your data shape. - No automatic activation. Always test (
/rules/ai/test), then/rules/ai/approveto save. Never go directly from generate to live. - AI usage is metered against the org's AI budget.