How to score Anthropic Claude answers with ClearRun

Get Claude's answer with the Anthropic SDK, join its text blocks, then pass the prompt and the text to clearrun.evaluate().

Last updated

Steps

  1. Install both

    npm install @anthropic-ai/sdk @clearrun/sdk
  2. Get an answer, then score it

    import Anthropic from '@anthropic-ai/sdk';
    import { createKernelClient } from '@clearrun/sdk';
    const clearrun = createKernelClient(); // reads CLEARRUN_API_KEY
    
    const anthropic = new Anthropic();
    const prompt = 'When was the Eiffel Tower finished?';
    
    const msg = await anthropic.messages.create({
      model: process.env.ANTHROPIC_MODEL,
      max_tokens: 1024,
      messages: [{ role: 'user', content: prompt }],
    });
    const answer = msg.content
      .filter((block) => block.type === 'text')
      .map((block) => block.text)
      .join('');
    
    const { verdict } = await clearrun.evaluate({ prompt, responseText: answer });
    console.log(verdict.score, verdict.verdictId);

In Claude Desktop or Claude Code instead?

Use the MCP server. See How to add ClearRun to Claude Desktop.