> ## 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.

# 根据纠正记录建议规则

> 根据最近一组路由纠正记录，生成一条安全的正则表达式规则。

针对指定模式，根据调用方最近的[纠正记录](/api-reference/routing-preferences/corrections)生成一条建议规则。分两级处理：

1. **优先使用确定性方法。** 一个纯辅助函数会在该纠正记录簇的提示词中提取文档频率（DF）最高的内容令牌，并组装出安全的 `\b(token1|token2|…)\b` 模式。已做供应商名称清洗。
2. **LLM 回退。** 如果确定性辅助函数没有返回任何结果（没有可用的令牌存留），Theo 会请求内部分类模型给出一条能匹配样本提示词的正则表达式。输出会被重新扫描以排查供应商名称，并在被信任前完成编译。若回退结果未通过任一检查，则返回 `404`，确保不安全的规则永远不会泄露出去。

该端点**不会**自动追加规则。调用方需要通过 [`PATCH /api/v1/routing-preferences/{id}`](/api-reference/routing-preferences/get-preference) 将建议规则 PATCH 到某个现有偏好设置上（或将其添加到新的偏好设置中）。

## 身份验证

需要携带具有 `billing` API 密钥作用域的 Bearer 令牌。

## 请求体

<ParamField body="expected_mode" type="string" required>
  你希望获取规则建议的 Theo 模式对应的纠正记录簇。
</ParamField>

## 请求示例

```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" }'
```

## 响应

```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` 为 `0.88`；当由 LLM 回退生成时，为 `0.78`。

## 错误

* `400 routing_suggest_below_threshold` — 所请求模式对应的纠正记录簇中，纠正记录数量未达到簇阈值。
* `404 not_found` — `expected_mode` 不存在对应的记录簇，或无法从现有样本中推导出安全的规则。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.