Complete worked example
python
def inspect_example(rows):
accepted, rejected = [], []
for index, row in enumerate(rows):
if not isinstance(row, dict):
rejected.append([index, 'object required'])
continue
version = row.get('schema_version', 1)
if version != 1:
rejected.append([index, 'unsupported schema'])
continue
identity, amount = row.get('id'), row.get('amount_cents')
if not isinstance(identity, str) or not identity.strip():
rejected.append([index, 'id required'])
elif type(amount) is not int:
rejected.append([index, 'integer cents required'])
else:
accepted.append({'id': identity.strip(), 'amount_cents': amount})
return {'accepted': accepted, 'rejected': rejected}- Reasoning
- The program checks schema version before interpreting its fields, then validates identity and amount. Accepted output drops source-only representation details and retains one canonical id and amount_cents shape. Each rejection names the failing rule and the source index so the delivery can be reconciled.