Turn your agents into perfection machines. The BaseEvaluation class is your quality assurance superhero - test, validate, and polish your agents until they shine.
// Check if response contains substring$this->assertResponseContains($response, 'expected text');// Check if response does NOT contain substring$this->assertResponseDoesNotContain($response, 'unwanted');// Regex pattern matching$this->assertResponseMatchesRegex($response, '/\d{3}-\d{4}/');// Check start and end of response$this->assertResponseStartsWith($response, 'Hello');$this->assertResponseEndsWith($response, '.');// Check for multiple substrings$this->assertContainsAnyOf($response, ['yes', 'sure', 'okay']);$this->assertContainsAllOf($response, ['thank', 'you']);// Check if response is not empty$this->assertResponseIsNotEmpty($response);
// Check if response is valid JSON$this->assertResponseIsValidJson($response);// Check if JSON contains specific key$this->assertJsonHasKey($response, 'result');
// Check if response is valid XML$this->assertResponseIsValidXml($response);// Check if XML contains specific tag$this->assertXmlHasValidTag($response, 'result');
// Reset assertion results (called automatically)$this->resetAssertionResults();// Get the CSV column name for prompts$columnName = $this->getPromptCsvColumn(); // Returns 'prompt' by default// Record custom assertion result$this->recordAssertion( 'customCheck', true, // status 'Custom check passed', 'expected', 'actual');
<?phpnamespace App\Evaluations;use Vizra\VizraADK\Evaluations\BaseEvaluation;class CustomerSupportEvaluation extends BaseEvaluation{ public string $agentName = 'customer_support'; public string $name = 'Customer Support Evaluation'; public string $description = 'Tests customer support agent responses'; public string $csvPath = 'app/Evaluations/data/support_tests.csv'; public string $promptCsvColumn = 'user_message'; // Custom column public function preparePrompt(array $csvRowData): string { $prompt = $csvRowData[$this->getPromptCsvColumn()] ?? ''; // Add customer context if available if (isset($csvRowData['customer_type'])) { $prompt = "Customer Type: " . $csvRowData['customer_type'] . "\n\n" . $prompt; } return $prompt; } public function evaluateRow(array $csvRowData, string $llmResponse): array { $this->resetAssertionResults(); // Basic quality checks $this->assertResponseIsNotEmpty($llmResponse); $this->assertNotToxic($llmResponse); $this->assertNoPII($llmResponse); // Test-specific assertions based on scenario $scenario = $csvRowData['scenario'] ?? ''; switch ($scenario) { case 'greeting': $this->assertResponseHasPositiveSentiment($llmResponse); $this->assertContainsAnyOf($llmResponse, ['hello', 'hi', 'welcome']); break; case 'complaint': $this->assertResponseContains($llmResponse, 'sorry'); $this->judge($llmResponse) ->using(PassFailJudgeAgent::class) ->expectPass('Response should be empathetic and helpful'); break; case 'technical_support': $this->assertReadabilityLevel($llmResponse, 10); $this->assertGrammarCorrect($llmResponse); break; } // Check for expected content if specified if (isset($csvRowData['must_contain'])) { $requiredTerms = explode(',', $csvRowData['must_contain']); $this->assertContainsAllOf($llmResponse, $requiredTerms); } // Determine overall pass/fail $allPassed = collect($this->assertionResults) ->every(fn($result) => $result['status'] === 'pass'); return [ 'row_data' => $csvRowData, 'llm_response' => $llmResponse, 'assertions' => $this->assertionResults, 'final_status' => $allPassed ? 'pass' : 'fail', ]; }}
CSV File Example:
user_message,scenario,customer_type,must_contain"Hello, I need help",greeting,new,help"My order hasn't arrived",complaint,vip,"sorry,assist""How do I reset my password?",technical_support,regular,"reset,password"
Structure your CSV files with clear columns for prompts, test scenarios, and expected outcomes.