Skip to main content

Introduction

Deck by PromptPHP includes an optional database tracking system that logs prompt versions and execution data. This enables:
  • Performance monitoring — Track token usage, latency, and cost per prompt version.
  • A/B testing — Compare performance metrics across different prompt versions.
  • Audit trails — Record what was sent to and received from AI providers.
  • Cost analysis — Monitor API spending per prompt, model, and provider.
  • User feedback — Attach ratings and comments to individual executions.
Tracking is entirely optional. Deck works fully without it.

Setup

Enable tracking

Set the tracking configuration in config/deck.php:
Or via environment variable:
By default, tracking is disabled when APP_DEBUG=true and enabled in production.

Publish migrations

Publish and run the migrations to create the required tables:

Database connection

By default, tracking uses your application’s default database connection. To store tracking data on a separate database:
The connection name must match a connection defined in config/database.php.

Database schema

prompt_versions table

Stores prompt version records and tracks which version is active. Indexes:
  • Unique index on (name, version) — ensures no duplicate versions per prompt.
  • Index on (name, is_active) — fast lookups for the active version.

prompt_executions table

Logs individual prompt executions with performance data. Indexes:
  • Index on (prompt_name, prompt_version, created_at) — fast filtering by prompt and time range.
The prompt_executions table does not have an updated_at column. Records are insert-only.

Recording executions

Manual tracking

Use the Deck::track() method to record an execution manually:
All fields in the data array are optional. You can track as little or as much as you need:
If tracking is disabled in configuration, the track() method is a safe no-op — you can call it without checking configuration first.

Automatic tracking via middleware

When using the Laravel AI SDK integration, the TrackPromptMiddleware handles tracking automatically. See AI SDK — Performance Tracking Middleware for setup details.

Tracked fields

Eloquent models

Deck provides two Eloquent models for interacting with tracking data.

PromptVersion

PromptPHP\Deck\Models\PromptVersion Represents a prompt version record in the prompt_versions table.
Fillable attributes: name, version, system_prompt, user_prompt, metadata, is_active Casts:

PromptExecution

PromptPHP\Deck\Models\PromptExecution Represents an execution record in the prompt_executions table.
Fillable attributes: prompt_name, prompt_version, input, output, tokens, latency_ms, cost, model, provider, feedback Casts:
PromptExecution sets UPDATED_AT = null since execution records are insert-only and never updated.

Factories

Both models include factories for testing.

PromptVersionFactory

Available states:

PromptExecutionFactory

Available states:

Querying execution data

Basic queries

Performance analysis

A/B testing

Compare metrics across prompt versions:

Cost analysis

Version management via database

When tracking is enabled, version activation is managed through the prompt_versions table instead of metadata.json files. This provides a centralised, queryable record of version history. The Deck::activate() method and prompt:activate command automatically use the appropriate storage (database or file) based on your tracking configuration.