Your LLM returned almost-valid JSON. Stop hand-patching it.
You asked the model for { id: number, active: boolean } . Here's what came back: { "id" : "42" , "active" : "true" , "role" : "admin" } Every field is almost right. id is a string. active is a string. There's a role you never asked for. And the whole thing is wrapped in a markdown code fence. So this: const user = User . parse ( JSON . parse ( raw )); // ๐ฅ throws twice โ once on the fence, andโฆ
The provided JSON from the LLM model contained several issues, including mismatched data types, missing fields, and incorrect formatting. For example, the "id" and "active" fields were strings instead of the expected number and boolean types, respectively. Additionally, the JSON was wrapped in a markdown code fence, which made parsing difficult. Furthermore, an extra "role" field was present that was not part of the requested schema.
Written by urgent.news from Dev.to's reporting โ not their text. Machine-written โ may contain errors; check the original before relying on it.