fix: convert UCCA findings/controls dicts to strings for response model
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -93,8 +93,8 @@ async def analyze_url(req: AnalyzeRequest):
|
|||||||
risk_score=assessment.get("risk_score", 0),
|
risk_score=assessment.get("risk_score", 0),
|
||||||
escalation_level=esc_level,
|
escalation_level=esc_level,
|
||||||
responsible_role=role,
|
responsible_role=role,
|
||||||
findings=findings if isinstance(findings, list) else [str(findings)],
|
findings=_to_string_list(findings),
|
||||||
required_controls=controls if isinstance(controls, list) else [str(controls)],
|
required_controls=_to_string_list(controls),
|
||||||
summary=summary,
|
summary=summary,
|
||||||
email_status=email_result.get("status", "failed"),
|
email_status=email_result.get("status", "failed"),
|
||||||
analyzed_at=datetime.now(timezone.utc).isoformat(),
|
analyzed_at=datetime.now(timezone.utc).isoformat(),
|
||||||
@@ -204,6 +204,20 @@ async def _assess(client: httpx.AsyncClient, text: str, classification: str) ->
|
|||||||
return {"risk_level": "unknown", "risk_score": 0, "escalation_level": "E0"}
|
return {"risk_level": "unknown", "risk_score": 0, "escalation_level": "E0"}
|
||||||
|
|
||||||
|
|
||||||
|
def _to_string_list(items: list) -> list[str]:
|
||||||
|
"""Convert list of dicts or strings to list of strings."""
|
||||||
|
result = []
|
||||||
|
for item in (items or []):
|
||||||
|
if isinstance(item, dict):
|
||||||
|
# UCCA returns {code, category, description} or {id, name, description}
|
||||||
|
desc = item.get("description", item.get("name", item.get("code", str(item))))
|
||||||
|
code = item.get("code", item.get("id", ""))
|
||||||
|
result.append(f"[{code}] {desc}" if code else str(desc))
|
||||||
|
else:
|
||||||
|
result.append(str(item))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _risk_to_escalation(risk_level: str) -> str:
|
def _risk_to_escalation(risk_level: str) -> str:
|
||||||
"""Map UCCA risk level to escalation level."""
|
"""Map UCCA risk level to escalation level."""
|
||||||
mapping = {
|
mapping = {
|
||||||
|
|||||||
Reference in New Issue
Block a user