Skip to main content

Overview

Prisma Schema Language (PSL) is the domain-specific language used to define your data model, database connection, and generator configuration in Prisma. This component is responsible for parsing, validating, and analyzing Prisma schema files.
PSL is the foundation of the entire Prisma stack. Every component—from the Schema Engine to the Query Compiler to Prisma Format—relies on PSL to understand your data model.

What is PSL?

PSL is a declarative language that lets you define:
  • Data models: Tables, collections, and their relationships
  • Fields: Columns with types, attributes, and constraints
  • Datasources: Database connection configuration
  • Generators: Client and other code generation settings
  • Enums: Enumerated types
  • Composite types: Embedded document types (MongoDB)

Example Schema

Architecture

The PSL implementation follows a layered architecture with clear separation of concerns:

Diagnostics

Error and warning collection, pretty printing, span tracking

Schema AST

Abstract syntax tree representation of the parsed schema

Parser Database

Semantic analysis and validation of the schema

PSL Core

Public API, configuration, and high-level operations

Dependency Graph

Crate Organization

The PSL codebase is organized into focused crates:

diagnostics

Handles errors, warnings, and diagnostic messages:
Features:
  • Error collection during parsing
  • Pretty-printed error messages with source context
  • Span tracking for precise error locations
  • Warning accumulation

schema-ast

Contains the Abstract Syntax Tree definitions:
Responsibilities:
  • Raw schema parsing
  • AST node definitions
  • Syntax validation
  • Comment preservation

parser-database

Provides semantic analysis and validation:
Features:
  • Attribute validation
  • Relation inference
  • Type checking
  • Constraint validation
  • Index and unique constraint handling

psl-core

High-level API and configuration:
Provides:
  • Schema validation entry point
  • Configuration parsing (datasources, generators)
  • Connector selection
  • Preview feature management

builtin-connectors

Database-specific validation and type systems:
  • PostgreSQL connector
  • MySQL connector
  • SQLite connector
  • SQL Server connector
  • MongoDB connector
  • CockroachDB connector
Each connector provides:
  • Native type mappings
  • Capability definitions
  • Database-specific validation rules
  • Default values and constraints

psl (Public API)

The main entry point used by other Prisma components:

Core Functionality

Schema Validation

The main validation flow:

Multi-File Schemas

Prisma supports splitting schemas across multiple files:

Configuration Parsing

Extract datasources and generators without full validation:

Schema Reformatting

Format Prisma schemas consistently:

Validation Features

Type Checking

Validates field types, ensures type compatibility, checks native type mappings

Relation Validation

Infers implicit relations, validates explicit relations, checks referential actions

Attribute Validation

Validates @id, @unique, @default, @relation, and all other attributes

Constraint Checking

Ensures unique constraints, validates indexes, checks composite keys

Attribute System

PSL supports field-level and block-level attributes: Field attributes (single @):
Block attributes (double @@):

Relation Inference

PSL can automatically infer simple relations:

Diagnostics and Error Reporting

PSL provides excellent error messages with source context:

Pretty Printing

The diagnostics crate provides formatted output:

Connector System

Connectors provide database-specific behavior:

Capabilities

Each connector declares its capabilities:
Common capabilities:
  • AutoIncrement
  • Enums
  • Json
  • FullTextSearch
  • MultiSchema
  • NamedForeignKeys
  • ScalarLists
  • And many more…

Preview Features

PSL supports preview features for experimental functionality:
Managing preview features:

Testing

PSL has three main test entry points:

1. Validation Tests

Declarative tests in psl/tests/validation/:

2. Reformat Tests

Tests in psl/tests/reformat/:

3. Unit Tests

Regular Rust tests in psl/tests/datamodel_tests.rs:
Validation tests are preferred for new tests—they’re declarative, fast to compile, and easy to maintain.

Configuration

Datasource Configuration

Parsed into:

Generator Configuration

Parsed into:

Native Type Mappings

Each connector maps Prisma types to database-native types:

Common Use Cases

Schema Validation in CI

Programmatic Schema Generation

Extracting Model Information

Prisma 7 Changes

In Prisma 7, url, directUrl, and shadowDatabaseUrl are no longer valid in the PSL datasource block. Connection strings are now provided externally by Prisma Client.
PSL now rejects these properties with helpful error messages:

Source Code

Explore the PSL source code:
  • Main crate: psl/psl/
  • Core logic: psl/psl-core/src/
  • Parser database: psl/parser-database/
  • Diagnostics: psl/diagnostics/
  • Contributing guide: psl/CONTRIBUTING.md
  • Repository: prisma/prisma-engines