parse_verdict#

scikitplot.corpus.parse_verdict(text, schema)[source]#

Parse a judge response strictly.

Parameters:
textstr

The response.

schemamapping

Required fields: name to spec, where a spec is ("bool",), ("str",), ("int", low, high), ("enum", values), ("list", item_spec) or ("obj", {name: spec}).

Returns:
dict

The verdict restricted to the schema’s fields, at every depth; fields beyond the schema are validated as JSON and then dropped, so a stored verdict holds only typed, finite, storable values.

Raises:
JudgeParseError

If the response is not exactly one JSON object (optionally inside one fenced code block); has duplicate keys, NaN/Infinity, a number that overflows to infinity, or nesting deeper than 128 containers; or a required field is missing, of another JSON type or range, or a string with a lone surrogate.

Parameters:
Return type:

dict[str, Any]

Examples

>>> parse_verdict('{"score": 4, "reason": "ok"}', {"score": ("int", 1, 5)})
{'score': 4}