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.

Example request:

import requests
import json
import os

url = "https://api.enkryptai.com/guardrails/detect-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',
    'api_key': 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:

{
	"adherence_score": 0.5
}