Cannot make exercise 2 work because result = constrained_gen(formatted) returns str instead of JSON object so it raises exception:
'str' object has no attribute 'issue_type'
As outlines documentation says, Outlines generation functions output plain strings by design, even when you restrict the model to a JSON schema. The library guarantees that the generated string adheres precisely to your constraints, but you must manually parse the returned text into a Python dictionary or object.
It’s impossible to edit ungraded cells. I tried to do an workaround with a custom constrained_gen function that parses the output to JSON before return it, but the string object I get before parsing is truncated (I don’t receive the full json string), and it raises:
Invalid JSON: EOF while parsing a string at line 1 column