firstResponsesGrammarViolation function
Describes the first Responses item/content-grammar violation in a
converted input list, or null when the payload is valid (issue #705).
This is the assertion half of sanitize-on-switch: the converter above is
expected to always produce valid items, so a non-null result names the
exact outbound record behind a grammar-shaped provider 400 (E5) instead
of leaving a bare body to decode. Content parts are checked against the
union of per-role part types (input_text/input_image/output_text);
the poison class is a type outside that set, not a role mixup.
Implementation
String? firstResponsesGrammarViolation(List<Map<String, dynamic>> input) {
for (var i = 0; i < input.length; i++) {
final violation = _inputItemViolation(input[i]);
if (violation != null) return 'input item $i: $violation';
}
return null;
}