GenkitG
Genkitโ€ข2y agoโ€ข
5 replies
thick-teal

When using claude models, I get a ~4%

When using claude models, I get a ~4% error rate with this message:
FAILED_PRECONDITION: Generation resulted in no candidates matching provided output schema.Candidate[0] SyntaxError: JSON5: invalid character '\n' at 3:0

But, the model returned valid JSON:
..."content":[{"text":"{\n... 

Claude isn't great at "JSON mode", so I ask it for JSON but pass in "text" as the output format, with the flow returning this output schema:
export const ReviewOutputSchema = defineSchema(
  "ReviewOutputSchema",
  z.object({
    summary: z.string().default(""),
    people: z.string().default(""),
    accomplishments: z.string().default(""),
    highlights: z.string().default(""),
    challenges: z.string().default(""),
    stateOfMind: z.string().default(""),
    quotes: z.array(z.string()).default([]),
  }),
);

When this error happens, the user runs the whole thing again and gets a successful response with the JSON not looking any different. Any ideas how to go about solving this?
Was this page helpful?