Document Analysis Example
This example demonstrates document attachment support (PDFs, Word docs, etc.) using PromptArena configuration and testing framework.
Overview
Section titled “Overview”PromptArena allows you to test document analysis workflows with multiple providers using declarative YAML configuration. This example shows how to:
- Attach PDF documents to prompts using media configuration
- Test document analysis across different LLM providers (Claude, Gemini)
- Run deterministic tests with mock providers for CI/CD
- Compare multiple documents or mix documents with images
Quick Start
Section titled “Quick Start”Run all scenarios with the mock provider (no API calls):
promptarena run config.arena.yaml --provider mock-docsRun with a real provider:
export ANTHROPIC_API_KEY=your-keypromptarena run config.arena.yaml --provider claude-docsConfiguration Structure
Section titled “Configuration Structure”document-analysis/├── config.arena.yaml # Main Arena configuration├── prompts/│ └── document-analyzer.yaml # Prompt with document media support├── providers/│ ├── claude-docs.provider.yaml # Claude configuration│ ├── gemini-docs.provider.yaml # Gemini configuration│ └── mock-docs.provider.yaml # Mock provider for testing├── scenarios/│ ├── pdf-summary.scenario.yaml # Single document analysis│ ├── multi-doc-compare.scenario.yaml # Multiple document comparison│ └── mixed-media.scenario.yaml # Document + image analysis├── mock-responses.yaml # Deterministic test responses└── test-docs/ # Sample test documents ├── sample.pdf ├── version1.pdf ├── version2.pdf ├── specs.pdf └── diagram.pngScenarios Explained
Section titled “Scenarios Explained”1. PDF Summary (pdf-summary.scenario.yaml)
Section titled “1. PDF Summary (pdf-summary.scenario.yaml)”Analyzes a single PDF document:
variables: user_question: "Please provide a brief summary of this document"
media: - type: document source: test-docs/sample.pdfRun it:
promptarena run config.arena.yaml --scenario pdf-summary --provider claude-docs2. Multi-Document Compare (multi-doc-compare.scenario.yaml)
Section titled “2. Multi-Document Compare (multi-doc-compare.scenario.yaml)”Compares multiple PDF documents:
variables: user_question: "Compare these documents and identify key differences"
media: - type: document source: test-docs/version1.pdf - type: document source: test-docs/version2.pdf - type: document source: test-docs/specs.pdfRun it:
promptarena run config.arena.yaml --scenario multi-doc-compare --provider claude-docs3. Mixed Media (mixed-media.scenario.yaml)
Section titled “3. Mixed Media (mixed-media.scenario.yaml)”Analyzes documents together with images:
variables: user_question: "Analyze the technical specifications and compare with the diagram"
media: - type: image source: test-docs/diagram.png - type: document source: test-docs/specs.pdfRun it:
promptarena run config.arena.yaml --scenario mixed-media --provider gemini-docsPrompt Configuration
Section titled “Prompt Configuration”The prompt template (prompts/document-analyzer.yaml) defines how media attachments are handled:
id: document-analyzername: Document Analyzersystem_template: | You are a document analysis assistant. Analyze documents carefully and provide clear, structured responses.
media: enabled: true types: - document - imageThis configuration:
- Enables media attachments
- Accepts both documents and images
- Works with multiple attachments in a single message
Provider Configuration
Section titled “Provider Configuration”Mock Provider (CI/CD Testing)
Section titled “Mock Provider (CI/CD Testing)”The mock provider (providers/mock-docs.provider.yaml) returns predefined responses without API calls:
id: mock-docsname: Mock Provider for Document Testsprovider: mock
mock_responses: file: mock-responses.yamlPerfect for:
- Automated testing in CI/CD pipelines
- Development without API costs
- Deterministic test outcomes
Claude Provider
Section titled “Claude Provider”Claude (providers/claude-docs.provider.yaml) supports PDFs up to 32MB:
id: claude-docsname: Claude with Document Supportprovider: claudemodel: claude-3-5-sonnet-20241022api_key: ${ANTHROPIC_API_KEY}Usage:
export ANTHROPIC_API_KEY=your-key-herepromptarena run config.arena.yaml --provider claude-docsGemini Provider
Section titled “Gemini Provider”Gemini (providers/gemini-docs.provider.yaml) supports PDFs up to 20MB:
id: gemini-docsname: Gemini with Document Supportprovider: geminimodel: gemini-1.5-proapi_key: ${GOOGLE_API_KEY}Usage:
export GOOGLE_API_KEY=your-key-herepromptarena run config.arena.yaml --provider gemini-docsProvider Capabilities
Section titled “Provider Capabilities”| Provider | Max Size | Formats | Notes |
|---|---|---|---|
| Claude | 32 MB | Native document support | |
| Gemini | 20 MB | Base64 inline data | |
| Mock | N/A | All | Deterministic responses |
Using Documents in Go Code
Section titled “Using Documents in Go Code”If you need to use document attachments programmatically (not via PromptArena):
import "github.com/altairalabs/promptkit/sdk"
// From fileresp, err := conv.Send(ctx, "Analyze this document", sdk.WithDocumentFile("path/to/document.pdf"))
// From memorypdfData, _ := os.ReadFile("document.pdf")resp, err := conv.Send(ctx, "Review this contract", sdk.WithDocumentData(pdfData, "application/pdf"))
// Multiple documentsresp, err := conv.Send(ctx, "Compare these documents", sdk.WithDocumentFile("v1.pdf"), sdk.WithDocumentFile("v2.pdf"))Testing in CI/CD
Section titled “Testing in CI/CD”Run with the mock provider for fast, deterministic tests:
promptarena run config.arena.yaml --provider mock-docs --ciThe --ci flag:
- Exits with non-zero status on failures
- Provides structured output
- Perfect for GitHub Actions, GitLab CI, etc.
Advanced: Custom Test Documents
Section titled “Advanced: Custom Test Documents”Replace files in test-docs/ with your own documents:
cp my-contract.pdf test-docs/sample.pdfpromptarena run config.arena.yaml --scenario pdf-summary --provider claude-docsOr create new scenarios in scenarios/ directory following the existing patterns.