Download the PHP package kent013/laravel-prism-prompt without Composer
On this page you can find all versions of the php package kent013/laravel-prism-prompt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kent013/laravel-prism-prompt
More information about kent013/laravel-prism-prompt
Files in kent013/laravel-prism-prompt
Package laravel-prism-prompt
Short Description Laravel Mailable-like API for LLM prompts with Prism
License MIT
Informations about the package laravel-prism-prompt
Laravel Prism Prompt
Laravel Mailable-like API for LLM prompts with Prism.
Define your prompts as YAML templates + PHP classes. Move text and model settings out of code, separate the system message from the user message, parse responses into typed DTOs, and observe every call via events with USD cost attached — the same way you'd compose a Mailable.
That's the whole loop. Everything else in this package is a layer on top: DTO mapping, multi-provider fallback, prompt-injection defence, parallel execution with prompt caching, observability, durable operations.
Installation
Publish config:
At a glance
| Need | Approach | Doc | Example |
|---|---|---|---|
| One-shot prompt with a YAML file | Prompt::load('name', $vars)->executeSync() |
yaml-template | 01 |
| Typed DTO response (legacy / text JSON) | Subclass + parseResponse() + extractJson() |
yaml-template | 02 |
| Schema-enforced DTO response (recommended) | Subclass + getJsonSchema() + parseStructured() |
structured-output | 13 |
| Send chat history natively | Override buildConversationMessages() |
yaml-template | 03 |
| Defend against prompt injection | UserInput::from() + DefensiveInstructions |
prompt-injection | 06 |
| Multi-provider fallback (BYOK) | YAML models[] + withApiKeys() |
providers | 08 |
| Parallel batch with shared cache | PromptPool::executeWithWarmup() |
parallel-execution | 09 |
Prompt caching on a single executeSync() |
sections: + withCacheBreakpoints() |
parallel-execution | — |
| Embeddings for RAG | EmbeddingPrompt |
embedding | 10 |
| Chat assistant w/ history + defence | Combine UserInput + history override + DTO |
prompt-injection | 11 |
| Multi-prompt pipeline (NPC reply → eval → hint) | Chain Prompt subclasses | yaml-template | 12 |
| Cost / usage / audit trail | Listen to PromptExecutionCompleted + withMetadata() |
events-and-cost | 05 |
| Cost / usage for pooled calls | PromptPool::executeWithWarmup() + $prompt->getPoolCallMeta() |
parallel-execution | 09 |
| Durable, resumable LLM operation | PromptOperation::for()->claimOrFollow() |
prompt-operation | 07 |
| Test mocked LLM calls | Prompt::fake() + assertions |
testing | 04 |
| Listener-based debug logs | PRISM_PROMPT_DEBUG=true |
debug-logging | — |
Settings priority
Settings resolve highest-wins:
- Class property (e.g.
protected ?float $temperature = 0.5) - YAML field
- Config default (
config('prism-prompt.default_*'))
Subclassing
Use Prompt::load() for the simplest case. When you need typed DTOs,
custom message construction, or fluent variables in __construct,
subclass:
Structured output (recommended for new code, since v0.15.0)
For prompts whose output must conform to a fixed shape, declare a Prism schema
via getJsonSchema(). The base will route the call through
Prism::structured() and pass the decoded array straight to
parseStructured() — no extractJson() regex, no YAML JSON example to drift
out of sync.
getJsonSchema() returning null (the default) keeps the legacy
Prism::text() + extractJson() path, so existing subclasses continue to work
unchanged. See docs/structured-output.md for the
full contract (event payload, fakes, error handling).
YAML lookup (in priority order):
$promptNameproperty — relative path fromprompts_path- Naming convention —
GreetingPrompt→greeting.yaml $promptsDirectory— group prompts under a subdirectory
getTemplatePath() is overridable for full control.
Configuration reference
config/prism-prompt.php
| Key | Default | Description |
|---|---|---|
default_provider |
anthropic |
Default LLM provider for text generation |
default_model |
claude-sonnet-4-5-20250929 |
Default model for text generation |
default_max_tokens |
4096 |
Maximum tokens in LLM response |
default_temperature |
0.7 |
Response randomness (0.0 - 1.0) |
default_embedding_provider |
openai |
Default provider for embeddings |
default_embedding_model |
text-embedding-3-small |
Default model for embeddings |
prompts_path |
resource_path('prompts') |
Base path for YAML templates |
cache.enabled |
true |
Enable YAML template caching |
cache.ttl |
3600 |
Cache TTL in seconds |
cache.store |
null |
Cache store (null = default) |
pool.concurrency |
5 |
Default PromptPool concurrency (env PRISM_PROMPT_POOL_CONCURRENCY) |
debug.enabled |
false |
Auto-register PerformanceLogListener |
debug.log_channel |
prism-prompt |
Log channel for debug output |
debug.save_files |
false |
Auto-register PerformanceDebugFileListener |
debug.storage_path |
storage_path('prism-prompt-debug') |
Directory for debug files |
config/prism-prompt-pricing.php
| Key | Default | Description |
|---|---|---|
pricing_source |
defaults_shipped |
Label embedded in every PricingSnapshot. Override via PRISM_PROMPT_PRICING_SOURCE |
unknown_model_behavior |
zero |
zero returns a zero-cost snapshot; throw raises InvalidArgumentException |
models.{provider}.{model} |
Anthropic Claude set | Per-million-token rates: input, output, optional cache_write / cache_read |
Documentation
In-depth topic guides live under docs/:
- yaml-template.md — YAML schema, message structure, override hierarchy
- structured-output.md —
getJsonSchema()/parseStructured()for Prism::structured() (v0.15.0+) - providers.md — multi-provider fallback, runtime API keys
- prompt-injection.md —
UserInput,DefensiveInstructions - parallel-execution.md —
PromptPoolwith prompt caching - events-and-cost.md — events,
withMetadata, USD cost - testing.md —
Prompt::fake()+ assertions - debug-logging.md — listener-based debug
- embedding.md —
EmbeddingPrompt - prompt-operation.md — durable, resumable operations
Runnable examples are under examples/:
| File | Topic |
|---|---|
| 01-basic-system-prompt.php | Quickest path with Prompt::load() |
| 02-json-dto-response.php | Subclass + extractJson() → DTO (legacy text path) |
| 13-structured-output.php | Subclass + getJsonSchema() → DTO (Prism::structured, v0.15.0+) |
| 03-conversation-history.php | Native chat history via buildConversationMessages() |
| 04-testing.php | Message-aware Prompt::fake() assertions |
| 05-events-and-cost.php | PromptExecutionCompleted listener + cost log |
| 06-user-input-defense.php | UserInput + DefensiveInstructions |
| 07-prompt-operation.php | PromptOperation durable workflow |
| 08-multi-provider-fallback.php | BYOK with auto provider selection |
| 09-prompt-pool-parallel.php | 5-axis rubric grading via PromptPool |
| 10-embedding-rag.php | RAG document indexing with EmbeddingPrompt |
| 11-chatbot-with-defense.php | Chatbot combining history + UserInput + DTO |
| 12-bundle-pipeline.php | Multi-prompt pipeline (NPC reply → eval → hint) |
License
MIT
All versions of laravel-prism-prompt with dependencies
echolabsdev/prism Version ^0.10|^0.99|^0.100|^1.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/view Version ^10.0|^11.0|^12.0|^13.0
react/async Version ^4.3
symfony/yaml Version ^6.0|^7.0|^8.0
webmozart/assert Version ^1.11|^2.0