Prompt Chain

Get Up-to-Date Answers with Citations

Promptfoo example testing Perplexity's search-augmented models: citations, structured output, filters, and reasoning.

Works with perplexity

92
Spark score
out of 100
Updated 24 days ago
Version code-scan-action-0.1
Models
gpt 4o

Add to Favorites

Why it matters

Leverage Perplexity's search-augmented chat models to obtain current information, complete with verifiable citations and structured outputs for specialized reasoning.

Outcomes

What it gets done

01

Access real-time information via web search.

02

Generate answers with supporting citations.

03

Obtain structured data outputs.

04

Utilize specialized reasoning capabilities.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-provider-perplexity | bash

Steps

Steps in the chain

01
Step 1: Basic Model Comparison
02
Step 2: Structured Outputs
03
Step 3: Advanced Search Filters
04
Step 4: Research and Reasoning

Overview

Provider Perplexity

A promptfoo example testing Perplexity's sonar search-augmented models across citations, structured output, search filtering, and deep research/reasoning, compared against a non-search baseline. Use when deciding whether Perplexity's search-augmented models fit a use case, comparing them against each other and a traditional model.

What it does

This example demonstrates how to use Perplexity's search-augmented chat models to get up-to-date answers with citations, structured outputs, and specialized reasoning. It covers real-time web search with academic citations, multiple specialized models for different use cases, structured outputs (JSON schema and regex patterns), date-range and location-based search filtering, search domain filtering for trusted sources, chain-of-thought reasoning, and deep research capabilities.

When to use - and when NOT to

Use this example when you need to evaluate Perplexity's search-augmented models against each other or against a traditional non-search model, validate structured output formats, or test advanced search filtering and reasoning capabilities. It is not a single-config example - it ships four separate configs, each demonstrating a distinct feature set, so pick the config matching what you need to test.

Inputs and outputs

Set PERPLEXITY_API_KEY and OPENAI_API_KEY (the latter for the comparison model in the basic example), then scaffold with npx promptfoo@latest init --example provider-perplexity and cd provider-perplexity. Four configs are provided: promptfooconfig.yaml compares Perplexity search models (sonar, lightweight; sonar-pro, advanced with high context; sonar-reasoning, fast step-by-step reasoning) against non-search GPT-4o-mini; promptfooconfig.structured-output.yaml demonstrates JSON schema enforcement for movie information and regex pattern matching for postal codes; promptfooconfig.search-filters.yaml shows date-range filtering, location-based results, and domain filtering for trusted sources; promptfooconfig.research-reasoning.yaml demonstrates sonar-deep-research (comprehensive research), sonar-reasoning-pro (advanced Chain of Thought reasoning), and r1-1776 (an offline model without search). Run any config with npx promptfoo@latest eval -c <config-file.yaml> and view results with npx promptfoo@latest view.

Integrations

Integrates the Perplexity API as a promptfoo provider across its sonar model family (sonar, sonar-pro, sonar-reasoning, sonar-reasoning-pro, sonar-deep-research) plus the offline r1-1776 model, alongside OpenAI's gpt-4o-mini as a non-search comparison baseline.

Who it's for

Teams deciding whether to use Perplexity's search-augmented models for up-to-date, cited answers, structured extraction, filtered search, or deep research/reasoning tasks, who need concrete comparisons against each other and against a traditional non-search model before choosing. Because the example is split into four independently runnable configs rather than one combined file, teams can start with just the comparison that matters most to them - for instance running only the structured-output config to validate JSON schema and regex extraction before ever touching the search-filtering or deep-research configs - and layer in the others once the first result looks promising, instead of having to understand every feature at once.

Source README

provider-perplexity (Perplexity API Examples)

This example demonstrates how to use Perplexity's search-augmented chat models to get up-to-date answers with citations, structured outputs, and specialized reasoning.

You can run this example with:

npx promptfoo@latest init --example provider-perplexity
cd provider-perplexity

Features Demonstrated

  • Real-time web search with academic citations
  • Multiple specialized models for different use cases
  • Structured outputs (JSON schema and regex patterns)
  • Date-range and location-based search filtering
  • Search domain filtering for trusted sources
  • Chain of thought (CoT) reasoning
  • Deep research capabilities

Environment Variables

This example requires the following environment variables:

  • PERPLEXITY_API_KEY - Your Perplexity API key from Perplexity Settings
  • OPENAI_API_KEY - Your OpenAI API key (for comparison model in basic example)

You can set these in a .env file or directly in your environment:

export PERPLEXITY_API_KEY=your_api_key_here
export OPENAI_API_KEY=your_api_key_here

Example Configurations

This example includes multiple configuration files to demonstrate different Perplexity features:

1. Basic Model Comparison (promptfooconfig.yaml)

Compares different Perplexity search models against a traditional non-search model (GPT-4o-mini):

  • sonar: Lightweight search model
  • sonar-pro: Advanced search model with high context
  • sonar-reasoning: Fast reasoning model with step-by-step thinking
npx promptfoo@latest eval -c promptfooconfig.yaml

2. Structured Outputs (promptfooconfig.structured-output.yaml)

Demonstrates Perplexity's structured output capabilities:

  • JSON schema enforcement for movie information
  • Regex pattern matching for postal codes
npx promptfoo@latest eval -c promptfooconfig.structured-output.yaml

3. Advanced Search Filters (promptfooconfig.search-filters.yaml)

Shows how to use advanced search filtering options:

  • Date range filtering for time-sensitive queries
  • Location-based results for geographical context
  • Domain filtering for trusted sources
npx promptfoo@latest eval -c promptfooconfig.search-filters.yaml

4. Research and Reasoning (promptfooconfig.research-reasoning.yaml)

Demonstrates specialized models for research and reasoning:

  • sonar-deep-research: Comprehensive research model
  • sonar-reasoning-pro: Advanced reasoning with Chain of Thought
  • r1-1776: Offline model without search capabilities
npx promptfoo@latest eval -c promptfooconfig.research-reasoning.yaml

Usage

After initializing the example, you can run any of the configurations:

cd provider-perplexity
npx promptfoo@latest eval -c <config-file.yaml>
npx promptfoo@latest view

What You'll Learn

These examples will show you how to:

  • Use different Perplexity models for specific tasks
  • Control search parameters for better results
  • Get structured outputs in specific formats
  • Utilize location and date-based filtering
  • Leverage specialized research and reasoning capabilities
  • Compare search-augmented models with traditional models

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.