fix: step3 _normalize_rule 处理 section 为 list 的 LLM 格式问题 - Closes #69
CI / test (pull_request) Successful in 9s
CI / test (pull_request) Successful in 9s
LLM 输出 section 字段有时为 list 而非 string,导致 .strip() 崩溃。 添加 _clean_section() 将 list→首元素 string,空 list 回退到 rule path。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -174,11 +174,25 @@ def _normalize_rule(rule: dict) -> dict:
|
||||
sources = rule.get("sources", [])
|
||||
valid_types = {"table", "text", "logic_tree"}
|
||||
|
||||
def _clean_section(val):
|
||||
"""Normalize section value: list→first element, ensure string."""
|
||||
if isinstance(val, list):
|
||||
return str(val[0]).strip() if val else ""
|
||||
if isinstance(val, str):
|
||||
return val.strip()
|
||||
return str(val).strip() if val else ""
|
||||
|
||||
# Normalize section fields that might be lists (LLM format instability)
|
||||
for s in sources:
|
||||
sec = s.get("section")
|
||||
if sec is not None:
|
||||
s["section"] = _clean_section(sec)
|
||||
|
||||
# try to infer a default section from the rule path
|
||||
default_section = ""
|
||||
for s in sources:
|
||||
sec = s.get("section", "")
|
||||
if sec and sec.strip():
|
||||
if sec and isinstance(sec, str) and sec.strip():
|
||||
default_section = sec.strip()
|
||||
break
|
||||
if not default_section:
|
||||
|
||||
Reference in New Issue
Block a user