Normalize known LLM type mistakes in a raw option dict before validation. Fixes observed in the top-1000 corpus run: - ``has_argument: null`` → ``False`` (8 positional-arg options) - ``has_argument`` list with int elements → stringified (hdparm --set-sector-size) - ``has_argument``
(raw: dict)
| 126 | |
| 127 | |
| 128 | def normalize_option_fields(raw: dict) -> dict: |
| 129 | """Normalize known LLM type mistakes in a raw option dict before validation. |
| 130 | |
| 131 | Fixes observed in the top-1000 corpus run: |
| 132 | - ``has_argument: null`` → ``False`` (8 positional-arg options) |
| 133 | - ``has_argument`` list with int elements → stringified (hdparm --set-sector-size) |
| 134 | - ``has_argument`` bare string (e.g. ``"1..99"``) → ``True`` (avrdude range params) |
| 135 | - sigil embedded in the positional name (``"positional": "@server"``) → |
| 136 | split into ``prefix`` + bare name; only for allowlisted sigil characters, |
| 137 | so placeholder styling like ``<FILE>`` is untouched |
| 138 | """ |
| 139 | raw = dict(raw) # shallow copy to avoid mutating caller's data |
| 140 | |
| 141 | if raw.get("has_argument") is None and "has_argument" in raw: |
| 142 | raw["has_argument"] = False |
| 143 | |
| 144 | # Normalize list elements to str (LLM sometimes returns ints for enum values). |
| 145 | ha = raw.get("has_argument") |
| 146 | if isinstance(ha, list) and ha and not all(isinstance(x, str) for x in ha): |
| 147 | raw["has_argument"] = [str(x) for x in ha] |
| 148 | |
| 149 | # Coerce bare strings (e.g. range expressions like "0..7") to True. |
| 150 | if isinstance(ha, str): |
| 151 | raw["has_argument"] = True |
| 152 | |
| 153 | # Strip a leading sigil from the positional name into prefix. |
| 154 | pos = raw.get("positional") |
| 155 | if ( |
| 156 | isinstance(pos, str) |
| 157 | and len(pos) > 1 |
| 158 | and pos[0] in models.OPTION_PREFIX_SIGILS |
| 159 | and not raw.get("prefix") |
| 160 | ): |
| 161 | raw["prefix"] = pos[0] |
| 162 | raw["positional"] = pos[1:] |
| 163 | |
| 164 | return raw |
| 165 | |
| 166 | |
| 167 | def sanitize_option_fields( |
no outgoing calls