> For the complete documentation index, see [llms.txt](https://api.farsight-ai.com/sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api.farsight-ai.com/sdk/metrics/custom-metrics.md).

# Custom Metrics

{% hint style="info" %}
Make sure you have your [OpenAI API Key](https://platform.openai.com/account/api-keys) before you begin.&#x20;
{% endhint %}

### Custom Metrics

`custom_metrics()`

Quickly create bespoke metrics to evaluate outputs based on other specific criteria. Implement constraints and automatically check if your LLM outputs meet these constraints. Returns a list of booleans: one for each guideline / constraint you provide.

<table><thead><tr><th width="155">Param</th><th width="303">Type</th><th>Description</th></tr></thead><tbody><tr><td>output</td><td>str</td><td>the response from your LLM</td></tr><tr><td>constraints</td><td>List[str]</td><td>List of constraints you want to check your LLM output against</td></tr></tbody></table>

<table><thead><tr><th width="156">Output Type</th><th>Output Definition</th></tr></thead><tbody><tr><td>List[str]</td><td><p>a list of booleans: one for each guideline you provide </p><p>"True" signifies that the output has violated the constraint</p></td></tr></tbody></table>

```python
from farsightai import FarsightAI

# Replace with your openAI credentials
OPEN_AI_KEY = "<openai_key>"

query = "Who is the president of the United States"
farsight = FarsightAI(openai_key=OPEN_AI_KEY)

# Replace this with the actual output of your LLM application
output = "As of my last knowledge update in January 2022, Joe Biden is the President of the United States. However, keep in mind that my information might be outdated as my training data goes up to that time, and I do not have browsing capabilities to check for the most current information. Please verify with up-to-date sources."
# Replace this with the actual constraints you want to check your LLM output for
constraints = ["do not mention Joe Biden", "do not talk about alcohol"]

custom_metric = farsight.custom_metrics(constraints, output)

print("score: ", custom_metric)
# score:  [True, False]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://api.farsight-ai.com/sdk/metrics/custom-metrics.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
