Skip to content

Commit

Permalink
Add optional strict validation to extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
rileytomasek committed Oct 17, 2024
1 parent e3b290e commit 7947e4b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/extract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export function createExtractFunction<Schema extends z.ZodObject<any>>(args: {
schema: Schema;
/** Add a system message to the beginning of the messages array. */
systemMessage: string;
/** Apply strict validation to the extracted data (default: true) */
strict?: boolean;
}): (input: string | Msg) => Promise<z.infer<Schema>> {
const { chatModel, schema, systemMessage } = args;
const { chatModel, schema, systemMessage, strict = true } = args;

async function runExtract(input: string | Msg): Promise<z.infer<Schema>> {
const inputVal = typeof input === 'string' ? input : (input.content ?? '');
Expand All @@ -33,7 +35,7 @@ export function createExtractFunction<Schema extends z.ZodObject<any>>(args: {
type: 'json_schema',
json_schema: {
name: args.name,
strict: true,
strict,
schema: zodToJsonSchema(schema, {
$refStrategy: 'none',
openaiStrictMode: true,
Expand Down

0 comments on commit 7947e4b

Please sign in to comment.