> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hitheo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Suggest a Rule From Corrections

> Generate a safe regex rule from a cluster of recent routing corrections.

Generates a single suggested rule derived from the caller's recent [corrections](/api-reference/routing-preferences/corrections) for a given mode. Two-tier:

1. **Deterministic first.** A pure helper extracts the highest-DF content tokens across the cluster's prompts and assembles a safe `\b(token1|token2|…)\b` pattern. Vendor-name-scrubbed.
2. **LLM fallback.** If the deterministic helper returns nothing (no surviving tokens), Theo asks an internal classifier model for a single regex that matches the sample prompts. Output is re-scanned for vendor names and compiled before being trusted. A fallback that fails either check returns `404` so no unsafe rule ever escapes.

The endpoint does **not** auto-append the rule. Callers PATCH the suggestion onto an existing preference (or add it to a new one) via [`PATCH /api/v1/routing-preferences/{id}`](/api-reference/routing-preferences/get-preference).

## Authentication

Requires a Bearer token with the `billing` API key scope.

## Body

<ParamField body="expected_mode" type="string" required>
  The Theo mode whose correction cluster you want a rule for.
</ParamField>

## Request Examples

```bash curl theme={null}
curl -X POST https://www.hitheo.ai/api/v1/routing-preferences/suggest-rule \
  -H "Authorization: Bearer $THEO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "expected_mode": "think" }'
```

## Response

```json theme={null}
{
  "suggested_rule": {
    "pattern": "\\b(clause|provision|indemnity)\\b",
    "target_mode": "think",
    "confidence": 0.88,
    "description": "Generated from 4 corrections that all routed to think."
  },
  "source_correction_ids": ["corr_a", "corr_b", "corr_c", "corr_d"],
  "confidence": 0.88
}
```

`confidence` is `0.88` when the deterministic helper produced the pattern, `0.78` when the LLM fallback did.

## Errors

* `400 routing_suggest_below_threshold` — Cluster for the requested mode has fewer corrections than the cluster threshold.
* `404 not_found` — No cluster exists for `expected_mode`, or no safe rule could be derived from the available samples.
