datawhalechina/hello-agents · error · Exception
Error '{repr(e)}' occurred while parsing the theorem '{theor
Error message
Error '{repr(e)}' occurred while parsing the theorem '{theorem}'. The theorem format is incorrect. What it means
An exception raised by SymbolicSolver._parse_theorem (src/gps/symbolic_solver.py) when parse_fact throws on the theorem string. The theorem is expected in the form Name(Upper,Case,Paras); parse_fact failing means the string deviates from that grammar — missing/mismatched parentheses, empty name, stray separators, or unbalanced quotes — and the code surfaces the underlying repr(e) plus the offending theorem text.
Source
Thrown at Co-creation-projects/BitSecret-GPSAgent/src/gps/symbolic_solver.py:1257
if old_goal_status[goal_id] != self.status_of_goal[goal_id]]
if len(updated_goal_ids) > 0:
result.append(
'部分目标的状态更新为(括号内数字表示目标状态,0表示此目标待求解,1表示此目标已求解,-1表示此目标不可能实现):'
)
for goal_id in updated_goal_ids:
goal = _anti_parse_fact((self.goals[goal_id][0], self.goals[goal_id][1]))
goal = goal + f'({self.status_of_goal[goal_id]})'
result.append(goal)
return '\n'.join(result)
def _parse_theorem(self, theorem):
try:
theorem_name, theorem_paras = parse_fact(theorem.replace(' ', ''))
except Exception as e:
e_msg = (f"Error '{repr(e)}' occurred while parsing the theorem '{theorem}'. "
f"The theorem format is incorrect.")
raise Exception(e_msg)
if theorem_name not in self.parsed_gdl["Theorems"]:
e_msg = f"Unknown theorem name: '{theorem_name}'."
raise Exception(e_msg)
error_paras = set([char for char in theorem_paras if not char.isupper()])
if len(error_paras) > 0:
e_msg = (f"Theorem parameters must be uppercase letters and , only. "
f"The current theorem contains invalid characters '{str(error_paras)}'.")
raise Exception(e_msg)
if len(theorem_paras) != 0 and len(theorem_paras) != len(self.parsed_gdl["Theorems"][theorem_name]['paras']):
e_msg = (f"'{theorem}' has wrong number of parameters "
f"(expected {len(self.parsed_gdl["Theorems"][theorem_name]['paras'])}).")
raise Exception(e_msg)
if len(theorem_paras) == 0:
theorem_paras = NoneView on GitHub (pinned to 606a07d341)
Solutions
- Look at the printed theorem string and align it to the exact 'Name(P1,P2,...)' grammar with ASCII parentheses and commas
- Add a lint step over your GDL/theorem file: try parse_fact(t.replace(' ','')) for each entry and report failures before runtime
- If importing data authored in Chinese IME, normalize full-width (), to (), before parsing
- Extend _parse_theorem's error path to include the expected format in the message for faster diagnosis
Example fix
# before (GDL entry) # theorem: "tangent_of_circle(O,A)" # full-width parens -> parse_fact raises # after # theorem: "tangent_of_circle(O,A)"
Defensive patterns
Strategy: validation
Validate before calling
def lint_theorem(t: str) -> bool:
t = t.replace(' ', '').replace('(', '(').replace(')', ')').replace(',', ',')
try:
name, paras = parse_fact(t)
return bool(name) and all(p.isupper() for p in paras)
except Exception:
return False
assert lint_theorem(theorem_str), f'malformed theorem: {theorem_str!r}' Type guard
def is_wellformed_theorem(t: str) -> bool:
t = t.replace(' ', '')
return '(' in t and t.endswith(')') and t.index('(') > 0 Try / catch
try:
solver._parse_theorem(theorem)
except Exception as e:
if 'format is incorrect' in str(e):
log_authoring_error(theorem=theorem, expected='Name(P1,P2,...)')
continue # skip bad entry, keep loading the rest
raise Prevention
- Normalize full-width parentheses/commas from CJK input before parsing
- Lint every theorem entry in GDL files with parse_fact during CI
- Keep the exact 'Name(Upper,Paras)' grammar when authoring theorem strings
When it happens
Trigger: Calling any API that loads or applies theorems — e.g. solving with a custom GDL, applying a theorem by name via the solver, or loading a theorem knowledge file — with a malformed entry like 'midpoint(' , ' (A,B)', 'isosceles_triangle,A,B', or a name containing spaces after the replace(' ','') normalizes away structure. The replace(' ','') happens before parsing, so whitespace inside the name silently concatenates tokens and can also produce this error.
Common situations: Hand-editing a GDL/theorem YAML and breaking parentheses; LLM-generated theorem strings with trailing commas or full-width Chinese parentheses () that parse_fact rejects; data files saved with trailing whitespace/newlines inside strings; name typos that drop the opening parenthesis entirely.
Related errors
- EE check not passed when add init fact {(predicate, instance
- Error when add init fact {(predicate, instance)}.
- Error when set init goal {self.parsed_cdl['goal_cdl']}.
- Unknown theorem name: '{theorem_name}'.
- Theorem parameters must be uppercase letters and , only. The
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/747eff9a0f787e17.
Report an issue: GitHub.