Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to have z.record part of structured outputs #1196

Open
1 task done
lifeiscontent opened this issue Nov 19, 2024 · 1 comment
Open
1 task done

add ability to have z.record part of structured outputs #1196

lifeiscontent opened this issue Nov 19, 2024 · 1 comment

Comments

@lifeiscontent
Copy link

Confirm this is a feature request for the Node library and not the underlying OpenAI API.

  • This is a feature request for the Node library

Describe the feature or improvement you're requesting

I'm currently working on a tool that provides edits to records the shape looks like:

model: string[][]

updates to model: Record<number, Record<number, string>>

the reason why this shape is ideal is because we can keep an in-memory lookup of all the "rows" and "columns" that have been edited and z.record is a good use case for this shape because we obviously don't need the entire array to be returned, just the edits. currently when using strict: true inside of a run, this kind of schema fails.

Additional context

No response

@silasalberti
Copy link

The OpenAI API doesn't support objects with dynamic fields (i.e. Record<number, string>): https://platform.openai.com/docs/guides/structured-outputs#additionalproperties-false-must-always-be-set-in-objects
So this is a current limitation of the OpenAI API, not the SDK.

A pragmatic workaround would be something like this:

model: z.array(
  z.object({
    row: z.number(),
    columns: z.array(
      z.object({
        column: z.number(),
        value: z.string(),
      }),
    ),
  }),
),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants