You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, i've been struggling to figure out why my zod schema doesn't work,
I'm using langchain's StrudturedOutputParser which uses zod internally,
The following is my schema:
import{z}from'zod';constPROPOSAL_CONTENT_TYPE=['header','list','table','text'];constTEXT_CONTENT_SCHEMA=z.object({type: z.string(),text: z.string().describe('Regular text content'),});constHEADER_CONTENT_SCHEMA=z.object({type: z.string(),size: z.number().describe('Header size: 1-3 (largest to smallest)'),text: z.string().describe('Header text'),});constLIST_CONTENT_SCHEMA=z.object({type: z.string(),ordered: z.boolean().optional().describe('Whether the list is numbered or not'),items: TEXT_CONTENT_SCHEMA.array().describe('Items of the list'),});constTABLE_CONTENT_SCHEMA=z.object({type: z.string(),headers: z.string().describe('Table headers must be unique and cannot be empty string, Must be set to appropriate value',).array().describe('Common headers shared by all items'),items: z.array(z.record(z.union([TEXT_CONTENT_SCHEMA,LIST_CONTENT_SCHEMA,z.lazy(()=>TABLE_CONTENT_SCHEMA),]),),).describe(`Array of objects representing rows of the table, field names must match the table headers if the items share common fields,Each field could contain a text, a list, or another table`),});exportconstPROPOSAL_SCHEMA_STRUCT=z.object({code: z.string().describe('Leave empty'),version: z.string().optional().describe('Leave empty'),title: z.string().describe('Title of the document'),date: z.string().describe('Date of the document'),company_name: z.string().describe('The target company for which the proposal is written'),content: z.array(z.union([HEADER_CONTENT_SCHEMA,LIST_CONTENT_SCHEMA,TABLE_CONTENT_SCHEMA,TEXT_CONTENT_SCHEMA,]),).describe(`Array of contents, each content can be one of: ${PROPOSAL_CONTENT_TYPE.toString()}The type of content determines the schema for that content`),});
The actual errors and data are much larger than these, i want to start by understanding the very first error.
As you can see the path specifies content[0].size, which is missing, but the "table" schema doesn't actually require size to be present.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, i've been struggling to figure out why my zod schema doesn't work,
I'm using langchain's StrudturedOutputParser which uses zod internally,
The following is my schema:
And here is a sample data:
Validating the above data against my schema fails with the following error:
The actual errors and data are much larger than these, i want to start by understanding the very first error.
As you can see the path specifies content[0].size, which is missing, but the "table" schema doesn't actually require size to be present.
Beta Was this translation helpful? Give feedback.
All reactions