//#region ../ai/src/utils/extract-json-lenient.d.ts /** * Lenient counterpart to {@link extractJsonPayload}, tuned for the * structured-output judges that emit *corrupted* JSON — notably the * Amazon Nova family, which routinely wraps its verdict in fenced * ` ```json ` blocks, prepends an explanation paragraph, or trails the * object with commentary. * * Where `extractJsonPayload` deliberately refuses the "first `{` … last * `}`" heuristic (it would corrupt strict callers when prose contains * stray braces), this helper *opts into* that resilience: after fence * stripping it scans for the first balanced JSON object (`{…}`) or array * (`[…]`) and returns just that slice. Brace/bracket counting is * string-aware (it ignores braces inside JSON string literals and honors * `\"` escapes), so prose-embedded braces inside the JSON's own strings * don't throw off the balance. * * Returns the fence-stripped, trimmed text unchanged when no balanced * structure is found, so the caller's `JSON.parse` still fails loudly on * genuine garbage rather than this helper inventing a value. * * **Trade-off:** resilience over strictness. Use it only where a tolerant * parse is wanted (the judge preset) — for normal structured output keep * `extractJsonPayload`, which fails fast on malformed responses so real * prompt/model defects surface instead of being silently papered over. * * @example * extractJsonLenient('Here is my verdict:\n```json\n{"score":0.9}\n``` — done.'); * // => '{"score":0.9}' * * @example * extractJsonLenient('The answer is {"verdict":"pass"} for sure.'); * // => '{"verdict":"pass"}' * * @example * extractJsonLenient('{"valid":true}'); * // => '{"valid":true}' (clean JSON passes through) */ declare function extractJsonLenient(text: string): string; //#endregion export { extractJsonLenient }; //# sourceMappingURL=extract-json-lenient.d.mts.map