JsonReply
The JSON in a model's reply, found the way llm4s itself finds it (#2952): LLMClient.completeStructured, an agent built with withOutput and AgentResult.decodeOutput all read a reply through this, so an application that reads one too - a middleware judging an answer before the agent accepts it, say - reads the same JSON they do.
A reply is read leniently, because models wrap JSON in prose and fences: a surrounding Markdown code fence is stripped and, when what is left is not JSON itself, the first balanced {...} or [...] block that parses is taken (string and escape aware), skipping earlier bracket pairs in the prose and anything after the JSON. At most 16 candidate starts are tried, so the cost stays linear in practice. A document nested more than 512 levels deep is refused: a value that deep overflows the stack of whatever reads it.
Attributes
- Source
- JsonReply.scala
- Graph
-
- Supertypes
- Self type
-
JsonReply.type
