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

# Relevancy

Analyses the relevance of a generated answer to a given question, ensuring that the response appropriately addresses the query. The detector returns a relevancy score indicating how well the answer relates to the question which will be between 0 and 1. 0 if it is relevant and 1 if it is not relevant at all. The detector also provides a list of atomic facts and their relevancy scores, along with the response latency.

## Example request:

<CodeGroup>
  ```python Python theme={"system"}
  import requests
  import json
  import os

  url = "https://api.enkryptai.com/guardrails/relevancy"
  payload = json.dumps({
  "question": "What is CV Raman known for?",
  "llm_answer": "C.V. Raman won the Nobel Prize for Physics in 1930 for his work on light scattering"
  })

  headers = {
      'Content-Type': 'application/json',
      'apikey': os.getenv('ENKRYPTAI_API_KEY')
  }

  response = requests.request("POST", url, headers=headers, data=payload)

  formatted_response = json.dumps(json.loads(response.text), indent=4)
  print(formatted_response)
  ```

  ```python Python SDK theme={"system"}
  import os
  from enkryptai_sdk import *
  from dotenv import load_dotenv

  load_dotenv()

  ENKRYPT_API_KEY = os.getenv("ENKRYPTAI_API_KEY")
  ENKRYPT_BASE_URL = os.getenv("ENKRYPTAI_BASE_URL") or "https://api.enkryptai.com"

  guardrails_client = GuardrailsClient(api_key=ENKRYPT_API_KEY, base_url=ENKRYPT_BASE_URL)

  question = "What is CV Raman known for?"

  llm_answer = "C.V. Raman won the Nobel Prize for Physics in 1930 for his work on light scattering"

  relevancy_response = guardrails_client.relevancy(
      question=question,
      llm_answer=llm_answer
  )

  print(relevancy_response)

  # Print as a dictionary
  print(relevancy_response.to_dict())
  ```
</CodeGroup>

## Example response:

```json JSON theme={"system"}
{
    "summary": {
        "relevancy_score": 0.0
    },
    "details": {
        "atomic_facts": [
            "The assistant greets with 'Hello!'.",
            "The assistant offers help today.",
            "The assistant invites questions or requests for assistance.",
            "The assistant is available to provide information.",
            "The assistant is available to provide support.",
            "The assistant asks if there is something specific to know or discuss."
        ],
        "relevancy_list": [
            0,
            0,
            0,
            0,
            0,
            0
        ],
        "relevancy_response": "{\n    \"chain_of_thought\": [\n        \"NOT RELEVANT: The fact is about greeting, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about offering help, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about inviting questions, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about providing information, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about providing support, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about asking for specific topics, not relevant to the question 'Hi'.\"\n    ],\n    \"relevancy\": [\n        0,\n        0,\n        0,\n        0,\n        0,\n        0\n    ]\n}",
        "relevancy_latency": 2.335660696029663,
        "compliance_mapping": {
            "owasp_llm_2025": [
                "LLM09:2025 Misinformation"
            ],
            "mitre_atlas": [],
            "nist_ai_rmf": [
                "MEASURE 2.6, MEASURE 2.13 (Output quality & appropriateness)"
            ],
            "eu_ai_act": [
                "Article 15(1) (Accuracy & performance requirements)"
            ],
            "iso_iec_standards": [
                "ISO/IEC 25024: 6.2.2 (Data quality & relevance metrics)"
            ]
        }
    }
}
```
