Analyses the adherence of a generated answer to a given context, ensuring that the response aligns with the provided information. The detector returns an adherence score indicating how well the answer adheres to the context which will be between 0 and 1. 0 if it adheres and 1 if it does not adhere at all. The detector also provides a list of atomic facts and their adherence scores, along with the response latency.

Example request:

import requests
import json
import os

url = "https://api.enkryptai.com/guardrails/adherence"
payload = json.dumps({
"llm_answer": "C.V. Raman won the Nobel Prize for Physics in 1930 for his work on making some science stuff or cooking stuff",
"context": "Indian scientists have made significant contributions to various scientific fields. C.V. Raman won the Nobel Prize for Physics in 1930 for his work on light scattering. Other notable scientists include Srinivasa Ramanujan, a mathematical genius, and A.P.J. Abdul Kalam, a key figure in India's aerospace and nuclear programs."
})

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)

Example response:

{
    "summary": {
        "adherence_score": 0.0
    },
    "details": {
        "atomic_facts": [
            "The speaker greets with 'Hello!'.",
            "The speaker offers help today.",
            "The speaker invites questions or requests for assistance.",
            "The speaker is available to provide information.",
            "The speaker is available to provide support.",
            "The speaker asks if there is something specific to know or discuss."
        ],
        "adherence_list": [
            0,
            0,
            0,
            0,
            0,
            0
        ],
        "adherence_response": "{\n    \"chain_of_thought\": [\n        \"TYPE 0: The context only contains the word 'Hi', which does not support the fact that the speaker greets with 'Hello!'. CORRECTED_FACT: NA\",\n        \"TYPE 0: The context does not mention the speaker offering help today. CORRECTED_FACT: NA\",\n        \"TYPE 0: The context does not mention the speaker inviting questions or requests for assistance. CORRECTED_FACT: NA\",\n        \"TYPE 0: The context does not mention the speaker being available to provide information. CORRECTED_FACT: NA\",\n        \"TYPE 0: The context does not mention the speaker being available to provide support. CORRECTED_FACT: NA\",\n        \"TYPE 0: The context does not mention the speaker asking if there is something specific to know or discuss. CORRECTED_FACT: NA\"\n    ],\n    \"faithfulness\": [\n        0,\n        0,\n        0,\n        0,\n        0,\n        0\n    ]\n}",
        "adherence_latency": 3.434762954711914
    }
}