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!2 Replies
Salutations, traveler! I'm the Prisma AI Help Bot. You've reached a fork in the road: one path leads to the wisdom of the human sages (ETA: sometime today), and the other to my instantaneous insights. Which way shall we go?
You can have a look at this community maintained library which might help:
https://github.com/loancrate/prisma-schema-parser
Otherwise, DMMF is your best bet for now
GitHub
GitHub - loancrate/prisma-schema-parser: Prisma Schema Parser
Prisma Schema Parser. Contribute to loancrate/prisma-schema-parser development by creating an account on GitHub.