evaluate_explanation
Assess AI explanation quality with OpenXAI metrics to validate accuracy and reliability for machine learning models. Supports PGI, PGU, RIS, and more.
Instructions
Evaluate explanation quality using OpenXAI metrics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| explanation | Yes | JSON string of the explanation to evaluate | |
| metric | Yes | Evaluation metric to use (PGI, PGU, RIS, RRS, ROS, etc.) | |
| model_info | Yes | Information about the model |
Implementation Reference
- index.js:768-815 (handler)The core handler function for the 'evaluate_explanation' tool. Validates the input metric against supported values, generates a Python code example demonstrating usage of OpenXAI's Evaluator class, and returns a formatted text response with evaluation details and code.async evaluateExplanation(metric, explanation, modelInfo) { const validMetrics = ['PGI', 'PGU', 'RIS', 'RRS', 'ROS', 'FA', 'RA', 'SA', 'SRA', 'RC', 'PRA']; if (!validMetrics.includes(metric)) { throw new Error(`Metric '${metric}' not supported. Available metrics: ${validMetrics.join(', ')}`); } const codeExample = ` # Example usage with OpenXAI: from openxai import Evaluator from openxai import LoadModel from openxai import Explainer from openxai.dataloader import ReturnLoaders # Load model and data model = LoadModel(data_name='${modelInfo.data_name}', ml_model='${modelInfo.ml_model}', pretrained=True) trainloader, testloader = ReturnLoaders(data_name='${modelInfo.data_name}', download=True) # Generate explanations explainer = Explainer(method='lime', model=model) inputs, labels = next(iter(testloader)) explanations = explainer.get_explanations(inputs) # Evaluate explanations evaluator = Evaluator(model, metric='${metric}') score = evaluator.evaluate( inputs=inputs, labels=labels, explanations=explanations ) print(f"${metric} score: {score}") `; return { content: [ { type: 'text', text: `Evaluated explanation using ${metric} metric\n\n` + `Metric: ${metric}\n` + `Dataset: ${modelInfo.data_name}\n` + `Model: ${modelInfo.ml_model}\n` + `Explanation: ${explanation}\n\n` + `Python code example:\n\`\`\`python${codeExample}\`\`\`` } ] }; }
- index.js:175-197 (schema)Input schema for the 'evaluate_explanation' tool, defining the expected parameters: metric (string enum of supported evaluation metrics), explanation (JSON string), and model_info (object with data_name and ml_model).inputSchema: { type: 'object', properties: { metric: { type: 'string', description: 'Evaluation metric to use (PGI, PGU, RIS, RRS, ROS, etc.)', enum: ['PGI', 'PGU', 'RIS', 'RRS', 'ROS', 'FA', 'RA', 'SA', 'SRA', 'RC', 'PRA'] }, explanation: { type: 'string', description: 'JSON string of the explanation to evaluate' }, model_info: { type: 'object', description: 'Information about the model', properties: { data_name: { type: 'string' }, ml_model: { type: 'string' } } } }, required: ['metric', 'explanation', 'model_info'] }
- index.js:172-198 (registration)Registration of the 'evaluate_explanation' tool in the ListToolsRequestSchema handler, including name, description, and full inputSchema. This makes the tool discoverable by MCP clients.{ name: 'evaluate_explanation', description: 'Evaluate explanation quality using OpenXAI metrics', inputSchema: { type: 'object', properties: { metric: { type: 'string', description: 'Evaluation metric to use (PGI, PGU, RIS, RRS, ROS, etc.)', enum: ['PGI', 'PGU', 'RIS', 'RRS', 'ROS', 'FA', 'RA', 'SA', 'SRA', 'RC', 'PRA'] }, explanation: { type: 'string', description: 'JSON string of the explanation to evaluate' }, model_info: { type: 'object', description: 'Information about the model', properties: { data_name: { type: 'string' }, ml_model: { type: 'string' } } } }, required: ['metric', 'explanation', 'model_info'] } },
- index.js:276-277 (registration)Dispatcher case in the CallToolRequestSchema handler that routes calls to the 'evaluate_explanation' tool to the evaluateExplanation method.case 'evaluate_explanation': return await this.evaluateExplanation(args.metric, args.explanation, args.model_info);