> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hipocap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scoring with Hosted Evaluators

## Creating a Basic Online Evaluator

This example walks through setting up a simple online evaluator that checks if an LLM response contains specific keywords, useful for content moderation or topic classification.

<Steps>
  <Step title="1. Navigate to Evaluators Page">
    From your Laminar dashboard, go to the Evaluators page and click "New Evaluator" to start creating your custom evaluation logic.
  </Step>

  <Step title="2. Define Your Evaluator Function">
    Create a Python function that analyzes the LLM output. This example checks for the presence of specific keywords and assigns a score based on relevance.

    **Important**: Online evaluator functions must return a single number as the score. The system automatically attaches this score to the span for monitoring and analysis.

    ```python theme={null}
    def keyword_checker(input):
        """
        Evaluator that checks if the output contains relevant keywords
        Returns a score from 0 to 1 based on keyword presence
        Note: Must return a single number as the score
        """
        def extract_text(data):
            if isinstance(data, str):
                return data
            if isinstance(data, dict) and 'content' in data:
                content = data['content']
                if isinstance(content, str):
                    return content
                if isinstance(content, list) and content:
                    first = content[0]
                    return first.get('text', str(first)) if isinstance(first, dict) else str(first)
            return str(data)
        
        text_content = extract_text(input)
        important_keywords = ['solution', 'help', 'recommend', 'suggest']
        
        keyword_count = sum(1 for keyword in important_keywords if keyword in text_content.lower())
        return min(keyword_count / len(important_keywords), 1.0)
    ```

    <Frame>
      <img src="https://mintcdn.com/hipocap/jGau1UNMEqA4k6Af/images/evaluations/online-evaluators/create-evaluator-function.png?fit=max&auto=format&n=jGau1UNMEqA4k6Af&q=85&s=88c4bc1f6569e07006babf85c7dfae70" alt="Create evaluator function" width="3012" height="1522" data-path="images/evaluations/online-evaluators/create-evaluator-function.png" />
    </Frame>
  </Step>

  <Step title="3. Test Your Evaluator">
    Use the test interface to verify your evaluator works correctly with sample inputs.

    ```python theme={null}
    {
        "content": [
            {"text": "Let me suggest a helpful approach"}
        ]
    }
    ```

    <Frame>
      <img src="https://mintcdn.com/hipocap/jGau1UNMEqA4k6Af/images/evaluations/online-evaluators/test.png?fit=max&auto=format&n=jGau1UNMEqA4k6Af&q=85&s=1c411cc9769ba2aa3566505b3f9227c9" alt="Test evaluator" width="3014" height="1522" data-path="images/evaluations/online-evaluators/test.png" />
    </Frame>
  </Step>

  <Step title="4. Register to Span Path">
    Navigate to your traces, find a span representing the LLM call you want to evaluate, and register your evaluator to that specific span path by clicking evaluators on span view.

    <Frame>
      <img src="https://mintcdn.com/hipocap/jGau1UNMEqA4k6Af/images/evaluations/online-evaluators/span-path.png?fit=max&auto=format&n=jGau1UNMEqA4k6Af&q=85&s=e99497677dfd2e6044fb0bc2319ff58f" alt="Register to span path" width="3014" height="1520" data-path="images/evaluations/online-evaluators/span-path.png" />
    </Frame>
  </Step>

  <Step title="5. Verify Automatic Execution">
    After registration, new spans on that path will automatically trigger your evaluator. Check the span details to see the attached evaluation scores.

    <Frame>
      <img src="https://mintcdn.com/hipocap/jGau1UNMEqA4k6Af/images/evaluations/online-evaluators/score.png?fit=max&auto=format&n=jGau1UNMEqA4k6Af&q=85&s=4501f9f63efb0d98ed3788a57d9d9ae1" alt="Verify execution - evaluator scores displayed in span" width="3012" height="1522" data-path="images/evaluations/online-evaluators/score.png" />
    </Frame>
  </Step>
</Steps>
