Pull a clean list of appendix-note strings from an analyst JSON result. Tolerant of shape: accepts a top-level ``appendix_notes`` list, a single string, or items wrapped in dicts with a ``note``/``content`` field. Returns ``[]`` for anything missing or malformed (so a non-compliant mode
(result: dict | None)
| 120 | |
| 121 | |
| 122 | def extract_appendix_notes(result: dict | None) -> list[str]: |
| 123 | """Pull a clean list of appendix-note strings from an analyst JSON result. |
| 124 | |
| 125 | Tolerant of shape: accepts a top-level ``appendix_notes`` list, a single |
| 126 | string, or items wrapped in dicts with a ``note``/``content`` field. Returns |
| 127 | ``[]`` for anything missing or malformed (so a non-compliant model degrades |
| 128 | gracefully to baseline body-only behavior). |
| 129 | """ |
| 130 | if not isinstance(result, dict): |
| 131 | return [] |
| 132 | raw = result.get("appendix_notes") |
| 133 | if raw is None: |
| 134 | return [] |
| 135 | if isinstance(raw, str): |
| 136 | raw = [raw] |
| 137 | if not isinstance(raw, list): |
| 138 | return [] |
| 139 | notes: list[str] = [] |
| 140 | for item in raw: |
| 141 | if isinstance(item, str): |
| 142 | text = item.strip() |
| 143 | elif isinstance(item, dict): |
| 144 | text = str(item.get("note") or item.get("content") or "").strip() |
| 145 | else: |
| 146 | text = "" |
| 147 | if text: |
| 148 | notes.append(text) |
| 149 | return notes |
| 150 | |
| 151 | |
| 152 | # ── Appendix consolidation (threshold-gated, paper Eq.11 UpdateSkillAppendix) ── |