Skip to content

Add a Zod schema adapter for prompt inputs #9

Description

@Cryptoteep

Context

promptkit's definePrompt currently accepts a free-form validate function. That's flexible but verbose for the common case where you just want to declare a schema and get types + validation for free.

Proposal

Add an optional schema adapter so users can write:

import { z } from 'zod'
import { definePrompt } from 'promptkit/zod'

const summarize = definePrompt({
  name: 'summarize',
  schema: z.object({
    text: z.string().min(1),
    maxLength: z.number().default(100),
  }),
  template: ({ text, maxLength }) =>
    `Summarize in ${maxLength} words: ${text}`,
})

The Zod schema would be used to:

  1. Validate input (replacing/combining with validate).
  2. Provide the TS type for template via z.infer.

Implementation notes

  • Put it in src/adapters/zod.ts, exported via promptkit/zod (a subpath export — needs a new entry in package.json exports).
  • Zod should be a peer dependency, not a runtime dep — keep the core zero-dep.
  • Add tests in tests/adapters/zod.test.ts.
  • Mirror the pattern for Valibot and ArkType in follow-up issues.

Acceptance

  • promptkit/zod subpath export works.
  • schema option infers template input type.
  • Validation errors are wrapped in ValidationError.
  • Tests + docs entry.

Good first issue?

Yes — well-scoped, mostly additive. Happy to pair on the design.

/label "good first issue" "help wanted" "adapter" "enhancement"

Metadata

Metadata

Assignees

No one assigned

    Labels

    adapterSchema/model adapters (Zod, OpenAI, etc.)enhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions