Skip to Content
🌐 IntegrationsLlms

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:

  1. Type @Docs in your prompt
  2. Add the URL: https://kysely.dev/llms-full.txt
  3. 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:

  1. Use @https://kysely.dev/llms-full.txt in your prompt
  2. Or add to .windsurfrules for 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:

  1. Mention you’re using Kysely in your prompt
  2. Reference the documentation URL
  3. 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:

  1. Include type definitions in your code. Copilot learns from your Database interface.
  2. Write descriptive comments that reference Kysely methods.
  3. 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 context

Claude 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 transactions

Type 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:

  1. Design your schema (with or without AI assistance)
  2. Run kysely-codegen to generate types
  3. AI assistants use the types to generate type-safe queries
  4. TypeScript validates the generated queries

Install kysely-codegen:

npm install -D kysely-codegen

Generate types from your database:

npx kysely-codegen --dialect postgres --out-file src/database.types.ts

Now 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 tables

Include type information:

Using this Database interface: [paste your types] Write a query that selects all people with their pets

Reference specific Kysely features:

Show me how to use Kysely's transaction() method to insert a person and their pets atomically

Ask for explanations:

Explain how Kysely's type inference works when I use .select() with multiple columns

Common 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:

  1. TypeScript compilation: Ensure the query compiles without errors
  2. Test execution: Run the query against a test database
  3. Review the SQL: Use .compile() to inspect the generated SQL
  4. Check performance: Use EXPLAIN to 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 helpers

Limitations 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.