Download the PHP package kevinpijning/pest-plugin-prompt without Composer

On this page you can find all versions of the php package kevinpijning/pest-plugin-prompt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pest-plugin-prompt

Pest Plugin for Prompt Testing

Tests PHP Version License Pest

Test your AI prompts with confidence using Pest's elegant syntax.

This plugin brings LLM prompt testing to your Pest test suite, powered by promptfoo under the hood. Write fluent, expressive tests for evaluating AI model prompts using the familiar Pest API you already love.

Table of Contents

Why Use This Plugin?

Prerequisites

Before you begin, make sure you have:

Setting up API Keys

Set environment variables for the providers you'll use:

If you're using Laravel or a similar framework with .env file support, you can add them there instead.

For more provider options and configuration, check out promptfoo's provider documentation.

Installation

Install the plugin via Composer:

The plugin automatically registers with Pest via package discovery - no additional configuration needed!

Quick Start

Here's the simplest possible example to get you started:

What's happening here?

  1. We create a prompt with variable interpolation using {{name}}
  2. We specify OpenAI's GPT-4o-mini as our LLM provider
  3. We test with the variable name set to "Alice"
  4. We assert that the response contains "Alice"

When you run this test, the plugin will:

Documentation

Core Functions

prompt()

Create a new evaluation with one or more prompts. Use {{variable}} syntax for variable interpolation.

provider()

Register a global provider like Pest datasets that can be reused across multiple tests. Providers registered with this function can be referenced by name in usingProvider().

assertion()

Register a reusable assertion group by name. Groups can be defined fluently or with a callback that receives the TestCase (and optional parameters), and then reused via to() / group() or magic toXxx methods.

Evaluation Methods

describe()

Add a description to your evaluation for better test output and debugging.

usingProvider()

Specify which LLM provider(s) to use for evaluation. You can pass provider IDs, Provider instances, callables, or registered provider names.

alwaysExpect()

Set default assertions and variables that apply to all test cases in the evaluation. This is useful when you want to ensure certain conditions are met for every test case without repeating the assertions.

With callback:

You can pass an optional callback function to configure the default test case:

Key points:

Use cases:

expect()

Create a test case with variables that will be substituted into your prompt template.

With callback:

You can pass an optional callback function that receives the created TestCase instance. This is useful for grouping multiple assertions or applying conditional logic.

and()

Chain multiple test cases for the same evaluation. Each call to and() creates a new test case with different variables.

With callback:

You can pass an optional callback function that receives the newly created TestCase:

to() and group()

Group multiple assertions together using a callback or invokable class. Both to() and group() are aliases that execute a callback with the current test case, allowing you to organize assertions logically.

Using callbacks:

Using invokable classes:

You can also pass an invokable class (a class with an __invoke() method) to reuse assertion logic across multiple tests.

Key points:

Use cases:

Assertion Methods

toContain()

Assert that the response contains specific text. Case-insensitive by default.

toContainAll()

Assert that the response contains all of the specified strings.

toContainAny()

Assert that the response contains at least one of the specified strings.

toContainJson()

Assert that the response contains valid JSON.

toContainHtml()

Assert that the response contains valid HTML.

toContainSql()

Assert that the response contains valid SQL.

toContainXml()

Assert that the response contains valid XML.

toEqual()

Assert that the response exactly equals the expected value. This is useful for deterministic outputs where you expect an exact match. You can also check whether it matches the expected JSON format.

toBe()

This is a convenience alias of toEqual().

toBeJudged()

Use an LLM to evaluate the response against a natural language rubric. This is useful for subjective quality checks.

startsWith()

Assert that the response starts with a specific prefix.

toMatchRegex()

Assert that the response matches a regular expression pattern.

toBeJson()

Assert that the response is valid JSON (not just contains JSON).

toEqualJson()

Assert that the JSON output exactly equals the expected value. Object key order is ignored, but array order is preserved. This is similar to Laravel's assertExactJson().

toMatchJsonStructure()

Assert that the JSON output contains all expected keys. This validates structure without checking values, similar to Laravel's assertJsonStructure().

toHaveJsonFragment()

Assert that the JSON output contains specific key-value pairs. Similar to Laravel's assertJsonFragment().

toHaveJsonFragments()

Assert that the JSON output contains all specified fragments.

toHaveJsonPath()

Assert that a value exists at a specific JSON path. Supports dot notation, numeric array indices, and wildcards.

toHaveJsonPaths()

Assert that multiple JSON paths exist, optionally with expected values.

toHaveJsonType()

Assert that the value at a JSON path has the expected type. Supports: string, number, boolean, array, object, null.

toBeHtml()

Assert that the response is valid HTML.

toBeSql()

Assert that the response is valid SQL (not just contains SQL).

toBeXml()

Assert that the response is valid XML.

toBeSimilar()

Assert that the response is semantically similar to the expected value using embedding similarity.

toHaveLevenshtein()

Assert that the Levenshtein (edit) distance between the response and expected value is below a threshold.

toHaveRougeN()

Assert that the ROUGE-N score is above a threshold.

toHaveFScore()

Assert that the F-score is above a threshold.

toHavePerplexity()

Assert that the perplexity is below a threshold.

toHavePerplexityScore()

Assert that the normalized perplexity score is below a threshold.

toHaveCost()

Assert that the inference cost is below a maximum threshold.

toHaveLatency()

Assert that the response latency is below a maximum threshold (in milliseconds).

toHaveValidFunctionCall()

Assert that the response contains a valid function call matching the provided schema.

toHaveValidOpenaiFunctionCall()

Assert that the response contains a valid OpenAI function call.

toHaveValidOpenaiToolsCall()

Assert that the response contains valid OpenAI tool calls.

toHaveToolCallF1()

Assert that the F1 score comparing actual vs expected tool calls is above a threshold.

toHaveFinishReason()

Assert that the model stopped for the expected reason. You can use either a string or the FinishReason enum.

Standard Finish Reasons:

Convenience Methods:

For each finish reason, there's a dedicated convenience method:

toBeClassified()

Assert that a HuggingFace classifier returns the expected class above a threshold.

toBeScoredByPi()

Use Pi Labs' preference scoring model as an alternative to LLM-as-a-judge.

toBeRefused()

Assert that the LLM output indicates the model refused to perform the requested task.

toPassJavascript()

Assert that a custom JavaScript function validates the output.

toPassPython()

Assert that a custom Python function validates the output.

toPassWebhook()

Assert that a webhook returns {pass: true}.

toHaveTraceSpanCount()

Assert that trace spans matching patterns meet min/max thresholds.

toHaveTraceSpanDuration()

Assert that trace span durations meet percentile and max duration thresholds.

toHaveTraceErrorSpans()

Detect errors in traces by status codes, attributes, and messages.

not Modifier

Negate any assertion by using the not modifier.

Provider Configuration

When creating or configuring providers, you can use these methods:

id()

Set the provider identifier (e.g., 'openai:gpt-4', 'anthropic:claude-3').

label()

Set a custom label for the provider (useful in test output).

temperature()

Control randomness in responses (0.0 to 1.0). Lower values make responses more deterministic.

maxTokens()

Set the maximum number of tokens to generate.

topP()

Set nucleus sampling parameter (0.0 to 1.0).

frequencyPenalty()

Penalize frequent tokens (-2.0 to 2.0).

presencePenalty()

Penalize new tokens based on presence in text (-2.0 to 2.0).

stop()

Set stop sequences where generation should stop.

config()

Set custom configuration options for the provider. Accepts either an array (replaces config) or a closure (receives current config for merging).

Extending Provider

The Provider class uses Pest's Extendable trait, allowing you to add custom methods:

Usage Examples

Basic Example

Multiple Prompts

Test multiple prompt variations against the same test cases.

Multiple Providers

Compare responses across different LLM providers.

Multiple Test Cases

Test the same prompt with different variable values.

Default Test Cases

Use alwaysExpect() to set assertions that apply to all test cases.

Provider Configuration

Configure providers with specific parameters.

Global Provider Registration

Register providers once and reuse them across tests.

Advanced Assertions

Combine multiple assertion types.

LLM-Based Evaluation

Use AI to evaluate response quality.

Structured JSON Output Testing

Test structured JSON outputs from LLMs, particularly useful with OpenAI's Responses API and structured output features.

Complex Example

A comprehensive example showing multiple features together.

CLI Options

--output

Save promptfoo evaluation results to a directory. Useful for debugging and analysis.

The output directory will contain HTML reports and JSON data from promptfoo evaluations.

Parallel Test Support

This plugin supports parallel test execution with Pest's --parallel flag. Cache isolation and merging is handled automatically.

Credits & License

Created by: Kevin Pijning

Built on the shoulders of giants:

License: MIT License

See the LICENSE file for full details.


Ready to start testing your prompts? Install the plugin and write your first test in under a minute. Happy testing!


All versions of pest-plugin-prompt with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
pestphp/pest Version ^4.0.0
pestphp/pest-plugin Version ^4.0.0
symfony/yaml Version ^7.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kevinpijning/pest-plugin-prompt contains the following files

Loading the files please wait ...