Last Updated: 3/20/2026
LLMs & AI Integration
Kysely provides LLM-friendly documentation to help AI coding assistants like Cursor, Windsurf, GitHub Copilot, ChatGPT, and Claude understand and generate type-safe database queries. This documentation is automatically generated and kept up-to-date with each release.
LLM Documentation Format
Kysely follows the llms.txt standard to provide structured documentation for AI tools. Two files are available:
llms.txt: A summary and index of all documentation pages. Use this for quick reference and navigation.
llms-full.txt: Complete documentation in a single file. Use this when you need comprehensive context for complex queries.
Both files are available at:
Using Kysely with AI Coding Assistants
Cursor
Cursor’s @Docs feature lets you reference external documentation:
- Type
@Docsin your prompt - Add the URL:
https://kysely.dev/llms-full.txt - Ask questions about Kysely queries
Example prompt:
@Docs https://kysely.dev/llms-full.txt
How do I write a query with a LEFT JOIN and WHERE clause?Cursor will fetch the documentation and use it to provide accurate, type-safe query examples.
Windsurf
Reference Kysely documentation in Windsurf:
- Use
@https://kysely.dev/llms-full.txtin your prompt - Or add to
.windsurfrulesfor persistent access:
# .windsurfrules
Use Kysely documentation from https://kysely.dev/llms-full.txt
for all database query generation.This makes Kysely documentation available in all Windsurf sessions.
ChatGPT and Claude
When using ChatGPT or Claude:
- Mention you’re using Kysely in your prompt
- Reference the documentation URL
- The AI will fetch and analyze the documentation
Example prompt:
I'm using Kysely (docs at https://kysely.dev/llms-full.txt).
Show me how to write a query that selects from multiple tables
with a subquery in the WHERE clause.Both ChatGPT and Claude can fetch external URLs and use them as context for generating code.
GitHub Copilot
GitHub Copilot doesn’t directly support external documentation URLs, but you can improve suggestions by:
- Include type definitions in your code. Copilot learns from your
Databaseinterface. - Write descriptive comments that reference Kysely methods.
- Use consistent patterns across your codebase.
Example:
// Use Kysely to select person with their pets using LEFT JOIN
const result = await db
.selectFrom('person')
.leftJoin('pet', 'pet.owner_id', 'person.id')
// Copilot will suggest appropriate methods based on contextClaude Code
Claude Code (the CLI tool) supports external documentation:
claude -p "Using Kysely docs at https://kysely.dev/llms-full.txt,
help me build a type-safe query with window functions"You can also reference the documentation in multi-turn conversations:
claude
> I'm using Kysely for database queries. The docs are at
https://kysely.dev/llms-full.txt
> Show me how to use transactionsType Definitions as Context
Your database schema types are valuable context for AI assistants. Include them in your codebase:
// database.types.ts
export interface Database {
person: {
id: number
first_name: string
last_name: string | null
age: number
}
pet: {
id: number
name: string
species: string
owner_id: number
}
}AI assistants can read these types and generate queries that:
- Reference only existing tables and columns
- Use correct types for comparisons and values
- Respect nullable columns
kysely-codegen for AI-Assisted Development
The kysely-codegen tool generates TypeScript types from your database schema. This creates a feedback loop for AI-assisted development:
- Design your schema (with or without AI assistance)
- Run kysely-codegen to generate types
- AI assistants use the types to generate type-safe queries
- TypeScript validates the generated queries
Install kysely-codegen:
npm install -D kysely-codegenGenerate types from your database:
npx kysely-codegen --dialect postgres --out-file src/database.types.tsNow AI assistants can reference your actual database schema when generating queries.
Effective Prompts for Query Generation
Structure your prompts to get better results from AI assistants:
Be specific about the query type:
Write a Kysely SELECT query that joins person and pet tablesInclude type information:
Using this Database interface: [paste your types]
Write a query that selects all people with their petsReference specific Kysely features:
Show me how to use Kysely's transaction() method to
insert a person and their pets atomicallyAsk for explanations:
Explain how Kysely's type inference works when I use
.select() with multiple columnsCommon AI-Generated Patterns
AI assistants trained on Kysely documentation typically generate correct patterns for:
Basic queries:
const people = await db
.selectFrom('person')
.select(['id', 'first_name', 'last_name'])
.where('age', '>', 18)
.execute()Joins:
const result = await db
.selectFrom('person')
.innerJoin('pet', 'pet.owner_id', 'person.id')
.select(['person.first_name', 'pet.name as pet_name'])
.execute()Transactions:
await db.transaction().execute(async (trx) => {
await trx.insertInto('person').values({ ... }).execute()
await trx.insertInto('pet').values({ ... }).execute()
})Subqueries:
const result = await db
.selectFrom('person')
.select('first_name')
.where('id', 'in', (eb) =>
eb.selectFrom('pet').select('owner_id')
)
.execute()Validating AI-Generated Queries
Always validate AI-generated queries:
- TypeScript compilation: Ensure the query compiles without errors
- Test execution: Run the query against a test database
- Review the SQL: Use
.compile()to inspect the generated SQL - Check performance: Use
EXPLAINto verify query plans
Example validation workflow:
// AI-generated query
const query = db
.selectFrom('person')
.innerJoin('pet', 'pet.owner_id', 'person.id')
.select(['person.first_name', 'pet.name'])
// Validate compilation
const compiled = query.compile()
console.log(compiled.sql)
console.log(compiled.parameters)
// Test execution
const result = await query.execute()
console.log(result)Teaching AI Assistants Your Patterns
AI assistants learn from your codebase. Establish patterns that AI can follow:
Consistent query structure:
// Always use this pattern for user queries
async function getUserById(id: number) {
return await db
.selectFrom('user')
.selectAll()
.where('id', '=', id)
.executeTakeFirstOrThrow()
}Reusable query fragments:
// Define common filters
const activeUsers = (eb: ExpressionBuilder<Database, 'user'>) =>
eb('status', '=', 'active')
// AI assistants will learn to use these
const result = await db
.selectFrom('user')
.selectAll()
.where(activeUsers)
.execute()Type-safe helpers:
// Create helpers for common operations
function withPets<DB, TB extends keyof DB>(qb: SelectQueryBuilder<DB, TB, any>) {
return qb.leftJoin('pet', 'pet.owner_id', 'person.id')
}
// AI assistants can suggest using these helpersLimitations and Best Practices
AI assistants are powerful but not perfect:
Limitations:
- May generate syntactically correct but semantically wrong queries
- Can hallucinate methods or features that don’t exist
- May not understand complex business logic
- Can produce inefficient queries
Best practices:
- Always review AI-generated code
- Test queries against real data
- Use TypeScript’s type checking as a first line of defense
- Keep your schema types up-to-date
- Provide clear, specific prompts
- Reference the Kysely documentation URL in prompts
What’s Next
- Generating Types: Learn about kysely-codegen and other type generation workflows to keep your schema in sync.