How to fix P6002: The provided data could not be serialized (Pulse) in Prisma

PrismaINTERMEDIATEHIGHUpdated Dec 29, 2025· 118 views

This error occurs when Prisma Pulse attempts to serialize database change events but encounters unsupported data types or circular references. It prevents real-time notifications from being transmitted to subscribers.

Quick fix

Fixes P6002

const prisma = new PrismaClient({
  log: [
    { level: 'query', emit: 'event' },
    { level: 'error', emit: 'stdout' },
  ],
});

prisma.$on('query', (e) => {
  console.log('Query: ' + e.query);
  console.log('Duration: ' + e.duration + 'ms');
});
  1. Verify which columns triggered the error
  2. Handle BigInt columns in subscriptions
  3. Convert Decimal fields to strings
  4. Exclude unsupported fields from subscription
prisma — error
const prisma = new PrismaClient({
log: [
{ level: 'query', emit: 'event' },
{ level: 'error', emit: 'stdout' },
],
});
prisma.$on('query', (e) => {
console.log('Query: ' + e.query);
console.log('Duration: ' + e.duration + 'ms');
});
P6002: The provided data could not be serialized (Pulse)

What this error means

The P6002 error indicates that Prisma Pulse is unable to serialize data from a database change event into a format suitable for transmission over the network. Prisma Pulse captures database changes and converts them into JSON-serializable events that subscribers receive. When the ORM encounters data types that cannot be serialized to JSON—such as BigInt, Decimal, Date objects, or circular references—it throws this P6002 error. This typically occurs when your database schema contains columns with types that JavaScript cannot natively serialize to JSON without special handling. The subscription fails because the change event cannot be transmitted to your application, breaking the real-time update pipeline. Understanding which data types are supported and how to handle them is essential for working with Prisma Pulse.

Typical symptoms

  • Prisma Pulse subscriptions fail when database changes occur
  • Error message: "P6002: The provided data could not be serialized"
  • Real-time updates stop working after insert or update operations
  • Subscription works for some tables but not others
  • Error occurs unpredictably when specific column types are modified
  • Application logs show serialization errors on database mutations

Common causes

  1. Schema contains BigInt columns and changes trigger serialization
  2. Decimal type fields (common in money/pricing) cannot be serialized by default
  3. Date or DateTime fields being included in change events
  4. Circular reference in JSON fields or relationships
  5. Bytes type in schema when referenced by subscription
  6. Custom types or objects that lack JSON serialization support
  7. Deep nesting in JSON columns containing unsupported types
  8. Using Prisma Decimal from @prisma/client/runtime/library

How to fix "P6002: The provided data could not be serialized (Pulse)"

1Verify which columns triggered the error

Enable Prisma query logging to identify which specific column is causing the serialization failure.

typescript
const prisma = new PrismaClient({
  log: [
    { level: 'query', emit: 'event' },
    { level: 'error', emit: 'stdout' },
  ],
});

prisma.$on('query', (e) => {
  console.log('Query: ' + e.query);
  console.log('Duration: ' + e.duration + 'ms');
});

Check your Prisma schema for BigInt, Decimal, Bytes, or nested Date fields in tables you're subscribing to.

2Handle BigInt columns in subscriptions

If your schema uses BigInt (common for IDs in large systems), Prisma Pulse cannot serialize them directly. Convert to String in the subscription response.

Schema:

prisma
model User {
  id        BigInt    @id @default(autoincrement())
  email     String    @unique
  score     BigInt
  createdAt DateTime  @default(now())
}

Subscribe with transformation:

typescript
const subscription = await prisma.user.subscribe({
  create: { after: true },
});

for await (const event of subscription) {
  // Manually convert BigInt to String for transmission
  const data = {
    ...event.after,
    id: event.after?.id?.toString(),
    score: event.after?.score?.toString(),
  };
  console.log('User change:', data);
}

This ensures BigInt values are converted to strings before they reach the serialization layer.

3Convert Decimal fields to strings

Prisma Decimal type is not natively JSON serializable. Use custom serialization in subscriptions.

Schema:

prisma
import Decimal from '@prisma/client/runtime/library';

model Product {
  id    String   @id @default(cuid())
  name  String
  price Decimal  @db.Decimal(10, 2)
}

Handle in subscription:

typescript
const subscription = await prisma.product.subscribe({
  create: { after: true },
  update: { after: true }
});

for await (const event of subscription) {
  // Convert Decimal to string for serialization
  const serializedData = {
    ...event.after,
    price: event.after?.price?.toString(),
  };
  console.log('Product change:', serializedData);
}

Always convert Decimal to string before sending over the network or storing in JSON fields.

4Exclude unsupported fields from subscription

If certain columns consistently cause serialization issues, exclude them from the subscription or filter them out after receiving the event.

typescript
// Instead of subscribing to entire record, subscribe to specific fields
const subscription = await prisma.user.subscribe({
  create: {
    after: true,
    // Pulse doesn't support field-level filtering yet, so filter in application
  }
});

for await (const event of subscription) {
  // Filter out problematic fields before processing
  const { problematicBigIntField, complexJSON, ...cleanData } = event.after || {};

  // Process only serializable data
  console.log('Clean data:', cleanData);

  // Handle excluded fields separately if needed
  if (problematicBigIntField) {
    console.log('BigInt field:', problematicBigIntField.toString());
  }
}

This prevents the serialization error by removing problematic columns from the change event before they reach the network layer.

5Update schema to use JSON-serializable types

The best long-term solution is to modify your schema to use only JSON-serializable types where possible, especially for frequently-changing columns.

prisma
// ❌ Problematic types
model BadExample {
  id      BigInt    @id  // Not serializable
  price   Decimal   @db.Decimal(10, 2)  // Not serializable
  data    Bytes     // Not serializable
  updated DateTime  // Tricky to serialize
}

// ✅ JSON-serializable alternatives
model GoodExample {
  id         String    @id @default(cuid())  // String is always safe
  price      String    @db.VarChar(20)       // String representation
  data       String    // Base64 or hex encoded
  updated    Int       // Unix timestamp (number)
  createdAt  String    @db.DateTime          // ISO string if needed separately
}

For new projects, use String IDs and represent numbers as strings or integers instead of specialized types.

Advanced notes

Serialization Deep Dive:

Prisma Pulse uses native JavaScript serialization, which only supports:
- string
- number (not BigInt)
- boolean
- null
- object (plain objects and arrays)
- undefined (in non-JSON contexts)

Prisma-specific types that cause P6002:
- BigInt: Use .toString() or change schema to String with @db.VarChar
- Decimal: Always convert to string via .toString()
- Date: Convert to ISO string via .toISOString()
- Bytes: Convert to hex or base64 string representation
- Symbol: Not serializable, remove from subscription payloads

Custom Serialization Handler:

Create a utility to safely serialize Pulse events:

typescript
function serializeForPulse(data: any): any {
  if (!data) return data;

  if (typeof data === 'bigint') {
    return data.toString();
  }

  if (data instanceof Decimal) {
    return data.toString();
  }

  if (data instanceof Date) {
    return data.toISOString();
  }

  if (Buffer.isBuffer(data)) {
    return data.toString('hex');
  }

  if (Array.isArray(data)) {
    return data.map(item => serializeForPulse(item));
  }

  if (typeof data === 'object') {
    return Object.entries(data).reduce((acc, [key, value]) => {
      acc[key] = serializeForPulse(value);
      return acc;
    }, {} as Record<string, any>);
  }

  return data;
}

const subscription = await prisma.user.subscribe({
  create: { after: true }
});

for await (const event of subscription) {
  const serialized = serializeForPulse(event.after);
  // Now safe to send over the network or store
  console.log('Serialized:', serialized);
}

Testing for Serialization Issues:

Before deploying to production, test that all your subscription payloads can be serialized:

typescript
async function testSubscriptionSerialization() {
  const testEvent = {
    after: await prisma.user.findFirst()
  };

  try {
    JSON.stringify(testEvent);
    console.log('✓ Event is serializable');
  } catch (error) {
    console.error('✗ Event contains non-serializable types:', error);
    // Fix the schema or add transformation logic
  }
}

Prisma Pulse Type Support Roadmap:

At the time of this writing, Prisma Pulse does not have special handling for BigInt, Decimal, or Bytes. The Prisma team has acknowledged these limitations. Monitor the [Prisma releases](https://github.com/prisma/prisma/releases) for built-in serialization helpers, which may eliminate the need for manual transformation in future versions.

In the meantime, always apply serialization transformations at the point of subscription to ensure reliable real-time updates.

Frequently asked questions

What does "P6002" mean?
The P6002 error indicates that Prisma Pulse is unable to serialize data from a database change event into a format suitable for transmission over the network. Prisma Pulse captures database changes and converts them into JSON-serializable events that subscribers receive. When the ORM encounters data types that cannot be serialized to JSON—such as BigInt, Decimal, Date objects, or circular references—it throws this P6002 error.
How do I fix "P6002"?
This error occurs when Prisma Pulse attempts to serialize database change events but encounters unsupported data types or circular references. It prevents real-time notifications from being transmitted to subscribers.
What causes "P6002"?
Schema contains BigInt columns and changes trigger serialization Decimal type fields (common in money/pricing) cannot be serialized by default Date or DateTime fields being included in change events
Is the "P6002" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading