PHPackages                             prismaticoder/laravel-prompt-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. prismaticoder/laravel-prompt-manager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

prismaticoder/laravel-prompt-manager
====================================

Laravel package for seamlessly managing, versioning and testing AI prompts when integrating with LLMs.

v1.0.0(1y ago)74.0k↑30%MITPHPPHP ^8.1CI passing

Since Apr 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/prismaticoder/laravel-prompt-manager)[ Packagist](https://packagist.org/packages/prismaticoder/laravel-prompt-manager)[ RSS](/packages/prismaticoder-laravel-prompt-manager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Laravel Prompt Manager
======================

[](#laravel-prompt-manager)

[![Tests](https://github.com/prismaticoder/laravel-prompt-manager/actions/workflows/tests.yml/badge.svg)](https://github.com/prismaticoder/laravel-prompt-manager/actions)[![Latest Stable Version](https://camo.githubusercontent.com/684fd5f55a81a3e7f7015319d052ffc16c225a9a2c028b47238277a7d3ad1be0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f707269736d617469636f6465722f6c61726176656c2d70726f6d70742d6d616e61676572)](https://packagist.org/packages/prismaticoder/laravel-prompt-manager)[![Total Downloads](https://camo.githubusercontent.com/59ff6e3d30176ca3d1529128264339b9b0afd60d135ebc30afcbc7e3edc81ba3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f707269736d617469636f6465722f6c61726176656c2d70726f6d70742d6d616e61676572)](https://packagist.org/packages/prismaticoder/laravel-prompt-manager)[![License](https://camo.githubusercontent.com/93d4c4a11eccddf29f1db6f41b1b0d57f708e6b4ab134ddd2f8d27c635fad9a7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f707269736d617469636f6465722f6c61726176656c2d70726f6d70742d6d616e61676572)](LICENSE)

A Laravel package built for the next generation of LLM engineers — seamlessly manage, version, and test your AI prompts with the same rigor you bring to your code. Designed for developers who want to apply real software engineering principles to prompt engineering and build AI features that scale with confidence.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Basic Usage](#basic-usage)
    - [Generating and Using Prompts](#generating-and-using-prompts)
- [Advanced Usage](#advanced-usage)
    - [Model-Specific Versions](#model-specific-versions)
    - [Working with Existing Template Storage](#working-with-existing-template-storage)
    - [A/B Testing Made Easy](#ab-testing-made-easy)
    - [Context-Aware Version Selection](#context-aware-version-selection)
    - [Custom Token Counting](#custom-token-counting)
- [Best Practices](#best-practices)
- [License](#license)

Features
--------

[](#features)

- 🔄 Prompt versioning
- 📊 Easy A/B testing with random selection
- 📏 Built-in token counting
- 🎯 Support for model-specific prompt variants
- 🧪 Simple testing and maintenance
- ⚡️ Fluent and intuitive API

Installation
------------

[](#installation)

```
composer require prismaticoder/laravel-prompt-manager
```

Basic Usage
-----------

[](#basic-usage)

Generate a new prompt class:

```
php artisan make:prompt ProductDescriptionPrompt
```

This will create a new `ProductDescriptionPrompt` class in the `App/Prompts` directory

```
namespace App\Prompts;

use Prismaticoder\LaravelPromptManager\BaseLLMPrompt;
use Prismaticoder\LaravelPromptManager\PromptVersionManager;

class ProductDescriptionPrompt extends BaseLLMPrompt
{
    private string $productName;
    private array $features;

    public function __construct(string $productName, array $features)
    {
        $this->productName = $productName;
        $this->features = $features;
    }

    protected function versions(): PromptVersionManager
    {
        return new PromptVersionManager([
            'v1' => fn() => $this->generateBasicPrompt(),
            'v1-creative' => fn() => $this->generateCreativePrompt(),
            'v1-technical' => fn() => $this->generateTechnicalPrompt(),
        ]);
    }

    protected function defaultVersion(): string
    {
        return 'v1';
    }

    private function generateBasicPrompt(): string
    {
        return version}" // v1
echo "Token count: {$result->token_count}";

// Specific version
$result = $prompt->generate('v1-creative');
```

Advanced Usage
--------------

[](#advanced-usage)

### Model-Specific Versions

[](#model-specific-versions)

Create model-specific prompts and dynamically select versions:

```
class CustomerSupportPrompt extends BaseLLMPrompt
{
    protected function defaultVersion(): string
    {
        return 'v1-gpt3.5'; // Only defaults to this version when no version selector is defined.
    }

    protected function versions(): PromptVersionManager
    {
        return new PromptVersionManager([
            'v1-gpt3.5' => fn() => $this->basePromptWithConstraints(2000),
            'v1-gpt4' => fn() => $this->basePromptWithConstraints(4000),
            'v1-claude' => fn() => $this->generateClaudePrompt(),
        ]);
    }

    protected function versionSelector(): Closure
    {
        return function(array $versions) {
            $model = config('services.llm.default_model');
            return match($model) {
                'gpt-4' => 'v1-gpt4',
                'claude' => 'v1-claude',
                default => 'v1-gpt3.5'
            };
        };
    }
}
```

### Working with Existing Template Storage

[](#working-with-existing-template-storage)

If you already store prompt templates in a database or registry, you can easily integrate them:

```
class TransactionFraudAnalysisPrompt extends BaseLLMPrompt
{
    private Transaction $transaction;
    private array $riskMetrics;

    public function __construct(Transaction $transaction, array $riskMetrics)
    {
        $this->transaction = $transaction;
        $this->riskMetrics = $riskMetrics;
    }

    protected function versions(): PromptVersionManager
    {
        return new PromptVersionManager([
            'v1' => fn() => $this->getTemplateAndCompile('standard'),
            'v2-high-risk' => fn() => $this->getTemplateAndCompile('high_risk'),
        ]);
    }

    private function getTemplateAndCompile(string $templateKey): string
    {
        // Fetch template from your existing storage
        $template = PromptTemplate::findByKey($templateKey);

        return collect([
            'amount' => $this->transaction->amount,
            'merchant' => $this->transaction->merchant_name,
            'risk_score' => $this->riskMetrics['score'],
        ])->reduce(
            fn(string $prompt, $value, $key) => str_replace("{{$key}}", $value, $prompt),
            $template
        );
    }

    protected function versionSelector(): Closure
    {
        return fn() => $this->riskMetrics['score'] > 0.7 ? 'v2-high-risk' : 'v1';
    }
}

// Usage example:
$prompt = TransactionFraudAnalysisPrompt::make($transaction, $riskMetrics);
$result = $prompt->generate(); // Version selected based on risk score
```

### A/B Testing Made Easy

[](#ab-testing-made-easy)

Easily run A/B tests on your prompts by enabling random version selection:

```
use Prismaticoder\LaravelPromptManager\Enums\VersionSelector;

class ProductCopyPrompt extends BaseLLMPrompt
{
    protected function versionSelector(): VersionSelector
    {
        return VersionSelector::RANDOM;
    }

    protected function defaultVersion(): string
    {
        return 'v1-formal'; // Only defaults to this version when no version selector is defined.
    }

    protected function versions(): PromptVersionManager
    {
        return new PromptVersionManager([
            'v1-formal' => fn() => $this->formalTone(),
            'v1-casual' => fn() => $this->casualTone(),
            'v1-persuasive' => fn() => $this->persuasiveTone(),
        ]);
    }
}
```

### Context-Aware Version Selection

[](#context-aware-version-selection)

You can override the default `versionSelector()` method to select prompt versions based on relevant context:

```
class TutorialPrompt extends BaseLLMPrompt
{
    private User $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    protected function versionSelector(): Closure
    {
        return fn() => match($this->user->expertise_level) {
            'beginner' => 'v1-basic',
            'intermediate' => 'v1-detailed',
            'expert' => 'v1-advanced',
            default => $this->defaultVersion()
        };
    }
}
```

### Custom Token Counting

[](#custom-token-counting)

The default token counting strategy is a simple estimation (text length divided by 4, based on [OpenAI's GPT tokenizer approximation](https://platform.openai.com/tokenizer)). To improve accuracy, you can override it with a custom token counter like Tiktoken:

```
class ComplexPrompt extends BaseLLMPrompt
{
    protected function tokenCounter(): Closure
    {
        return fn(string $prompt) => Tiktoken::count($prompt);
    }
}
```

Best Practices
--------------

[](#best-practices)

- **Abstract Complex Prompts**: Break down large prompts into smaller methods.
- **Semantic Versioning**: Use clear naming conventions (e.g., `v1-gpt4`, `v1-formal`).
- **Testing**: Use built-in random selection for effective A/B testing.

License
-------

[](#license)

The MIT License (MIT). See [License File](LICENSE).

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance46

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

400d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ab0df489cdc34db960e0abba651597437b6c340aece35a0aaefb09e070495d1?d=identicon)[prismaticoder](/maintainers/prismaticoder)

---

Top Contributors

[![prismaticoder](https://avatars.githubusercontent.com/u/28912838?v=4)](https://github.com/prismaticoder "prismaticoder (39 commits)")

---

Tags

ailaravellaravel-packagellmnlpprompt-engineeringlaravelailaravel-packageopenainlpllmgptartificial intelligenceChatGpttext-generationpromptlanguage modelsprompt-engineeringlaravel-prompt

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/prismaticoder-laravel-prompt-manager/health.svg)

```
[![Health](https://phpackages.com/badges/prismaticoder-laravel-prompt-manager/health.svg)](https://phpackages.com/packages/prismaticoder-laravel-prompt-manager)
```

###  Alternatives

[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[helgesverre/toon

Token-Oriented Object Notation - A compact data format for reducing token consumption when sending structured data to LLMs

11841.4k9](/packages/helgesverre-toon)[claude-php/claude-php-sdk-laravel

Laravel integration for the Claude PHP SDK - Anthropic Claude API

5010.8k](/packages/claude-php-claude-php-sdk-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
