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.
Setup
Enable tracking
Set the tracking configuration inconfig/deck.php:
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: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 theDeck::track() method to record an execution manually:
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, theTrackPromptMiddleware 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.
name, version, system_prompt, user_prompt, metadata, is_active
Casts:
PromptExecution
PromptPHP\Deck\Models\PromptExecution
Represents an execution record in the prompt_executions table.
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
PromptExecutionFactory
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 theprompt_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.