Interface ParseJsonOptions<_T>

Options for safe JSON parsing.

interface ParseJsonOptions<_T> {
    attemptFixWithLLM?: boolean;
    llmModelIdForFix?: string;
    llmProviderIdForFix?: string;
    targetSchema?: JSONSchemaObject;
    maxRepairAttempts?: number;
}

Type Parameters

  • _T = any

Properties

attemptFixWithLLM?: boolean

If true, attempts to use an LLM to fix or extract JSON if standard parsing fails.

llmModelIdForFix?: string

The model a repair calls. LLMUtilityAI: else its jsonFixerModelId, else its defaultModelId.

llmProviderIdForFix?: string

The provider a repair calls. LLMUtilityAI: else its defaultProviderId.

targetSchema?: JSONSchemaObject

Optional JSON schema (draft-07) to validate the parsed object against, with Ajv. The standard formats are checked (date-time, email, uri and the others of ajv-formats), a keyword Ajv does not know is passed over, as JSON Schema says, and so is a format it does not know, and a value is coerced to the type its schema names where it can ("5" to 5) in the value answered. The schema may be built anew for every call, under the same $id too. StatisticalUtilityAI answers null for a value that fails it. LLMUtilityAI sends a value that fails it for repair as it sends a text that does not parse, names the schema (and a parsed value's errors) in the repair request, and answers null when no repair passes it. No value passes a schema Ajv cannot compile, a schema under the draft-07 meta-schema's $id or a schema marked $async: both classes answer null, and LLMUtilityAI asks for no repair.

maxRepairAttempts?: number

LLMUtilityAI: how many repairs to try, each on the text the last one answered, while a repair does not parse or fails targetSchema. 1 unless it is a whole number of 1 or more, so Infinity is 1 too.