Views
No views yet
1import json
2
3def parse_attempt(text):
4 candidates = []
5 if "```" in text:
6 for p in text.split("```"):
7 p = p.strip().lstrip("json").strip()
8 candidates.append(p)
9 candidates.append(text.strip())
10 s, e = text.find("{"), text.rfind("}") + 1
11 if s != -1 and e > s:
12 candidates.append(text[s:e])
13
14 for c in candidates:
15 try:
16 r = json.loads(c)
17 if isinstance(r, dict) and "action_type" in r:
18 # 1. Guarantee required reasoning
19 r.setdefault("reasoning", "No reasoning provided.")
20
21 # 2. Enforce strict enums for violation_category
22 valid_cat = {"HEALTHCARE", "FINANCIAL", "NONE", None}
23 if r.get("violation_category") not in valid_cat:
24 r.pop("violation_category", None)
25
26 # 3. Nuke hallucinated extra fields
27 allowed = {"action_type", "reasoning", "violation_category", "metadata"}
28 return {k: v for k, v in r.items() if k in allowed}
29 except Exception:
30 continue
31 return Nonequery_regulations and analyze_image), it currently struggles with strict terminal sequence chaining. Specifically, the agent frequently fails to explicitly call the submit_audit action before attempting to issue a final approve or reject decision, resulting in an incomplete task execution.