Function: extractDraftJson()
function extractDraftJson(raw: string): ExtractDraftResult;Defined in: server/insights/ask/parse-draft.ts:96
Pull the JSON object out of a model's textual answer.
Lenient by design — it tolerates a markdown fence, a preamble, or trailing
commentary. Leniency costs nothing here: whatever comes out is still validated
against reportDefinitionSchema AND validateDefinition before anything can
run, so the only thing strictness would buy is a different rejection message.
When more than one balanced object survives parsing, a recognizable answer
wins, and a DEFINITION outranks a refusal. The two are not symmetric
downstream: a definition still faces both validators and a bounded retry,
whereas AskService turns error into a terminal ask-unanswerable with no
retry at all. So an illustrative {"error": …} in a preamble must not be able
to discard a usable definition that follows it. With nothing recognizable, the
first parseable object is used.
Parameters
| Parameter | Type |
|---|---|
raw | string |