genkit icon indicating copy to clipboard operation
genkit copied to clipboard

[JS] dotprompt doesn't propagate input/output schemas in typescript

Open sqrrrl opened this issue 1 year ago • 3 comments

Describe the bug

Schemas in dotprompt managed prompts don't propagate through to typescript. Input and output types are 'unknown'.

To Reproduce

  • Definte a dotprompt file with input & output schemas. Any of the examples from https://firebase.google.com/docs/genkit/dotprompt#defining_inputoutput_schemas_with_picoschema
  • Initialize the prompt and write code to call generate
  • Note that input type in typescript is 'unknown'. The type for the data() or object() on the response is also 'unknown'

Expected behavior Input/output types are correctly typed.

At a minimum, update documentation to indicate that dotprompt prompts don't expose it.

sqrrrl avatar May 29 '24 20:05 sqrrrl

Thanks for the report! This is a known limitation as there's no way for us to dynamically infer a strong type from a text template, but you're right that we should probably document it.

I've filed #417 as one way to help with this problem but you're right that we should at least document it.

mbleigh avatar Jun 14 '24 19:06 mbleigh

Figured as much. Like the idea of being able to reference schema defined in code, that would help with the duplication.

Alternate would be a preprocessor/generator to export the types from dotprompt files.

sqrrrl avatar Jun 14 '24 21:06 sqrrrl

Yep a build step is something I've thought about (even played with a bit at one point).

mbleigh avatar Jun 14 '24 22:06 mbleigh

@mbleigh still relevant?

chrisraygill avatar Dec 14 '24 00:12 chrisraygill

I'm going to say that this is mitigated by defineSchema.

const MySchema = ai.defineSchema('MySchema', z.object({...});
---
input:
  schema: MySchema
---

it'd be nice to have something even more magical, but this is workable for now.

mbleigh avatar Dec 14 '24 00:12 mbleigh