#Zod .describe() causing issues with schema validation

6 messages · Page 1 of 1 (latest)

pliant snow
#

I'm seeing the following when running npx convex dev

✖ Error: Unable to run schema validation on https://sensible-salmon-524.convex.cloud
[CONVEX] Error fetching POST  https://sensible-salmon-524.convex.cloud/api/prepare_schema 400 Bad Request: Error: Hit an error while evaluating your schema:
[CONVEX] Uncaught TypeError: Cannot read properties of undefined (reading 'describe')
[CONVEX]     at <anonymous> (../types/fireview/filters/zod.ts:62:12)

The code in that file looks like this:

export const zFireviewWhereFilter = z.object({
  value: z.union([
    z
      .object({
        type: z.literal("static"),
        value: z
          .any()
          .describe(
            "The static value to filter on. This should match the type of the field."
          ),
      })
      .describe("A filter value that is a static value"),
    z
      .object({
        type: z.literal("dynamic"),
        queryValue: z.union([
          zDocumentFieldFromPathQuery.describe(
            "Used when the dynamic value is a field from a document."
          ),
          zFirstNDocumentFieldsQuery.describe(
            "Used when the dynamic value is a list of fields from several documents."
          ),
          zDocumentFieldAggregationQuery.describe(
            "Used when the dynamic value is an aggregation of a field."
          ),
        ]),
      })
      ),
  ]),
});

This is put into a table like so:

 v.object({
      ...vCommonFilterExpressionFields.fields,
      ...vFireviewWhereFilter.fields,
    })

where

export const vFireviewWhereFilter = zodToConvex(zFireviewWhereFilter);

When i remove the describe lines I don't see the same error so I'm wondering if zodToConvex is doing something weird

#

For context, i need those descriptions to reuse these data types in tools to agents so they have more context

#

This issue might be related to #1278052485344399370

pliant snow
#

due to circular dep issue, was just really not obvious - sharing in case anyone gets weird errors like this - was not a convex issue

gray forge
#

thanks for the follow up

#

it's really a bummer how often circular issues cause some of the most confusing errors