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