cadrumo.adapters.outbound.llm.response_json module¶
Locating a JSON object inside a model reply.
A small model routinely wraps its answer in a code fence or a sentence, so the object has to be located rather than assumed to be the whole reply. Two response parsers each carried an identical copy of that search; this is the one they now share.
- first_json_object(text)[source]¶
Return the first complete JSON object in
textas its source substring, orNone.The SUBSTRING rather than the decoded object, so validation runs in pydantic’s JSON mode. Strict validation of an already-decoded object would refuse a JSON array where the schema declares a tuple – which every real reply carries, because JSON has no tuple.
Decoding is delegated to the stdlib decoder, which knows where an object ends.