PrismaP
Prisma9mo ago
2 replies
Risatoga

Easy way to programmatically access Prisma schema for AI assistant integration?

I'm building an AI assistant for my Next.js app that needs to know about my database schema to generate proper queries.

Current challenge: I need a way to programmatically extract model/table definitions from my Prisma schema at runtime without manually hardcoding the schema description every time my models change.

I've seen that Prisma has a DMMF (Data Model Meta Format) that can be accessed via Prisma.dmmf, but it feels overly complex for my use case. I also have Zod also don't know how to generate something that the ai can use at runtime.

Ideal solution: A simple utility that can extract field names, types, relationships and constraints from my existing Prisma models to provide as context to my OpenAI assistant.

Has anyone solved this elegantly? Looking for the most maintainable approach where schema changes automatically propagate to my AI tools.

Thanks!
Was this page helpful?