> ## 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.

# Topic Detector

Analyzes text to determine if it aligns with the given specific topic or field of interest. You can provide the topic keyword as a string or a list of strings. The detector returns a binary value (0 for off-topic, 1 for on-topic) as summary value indicating whether the text aligns with the given topic. The output will contain the most likely topic among those provided and returns details for only that topic.

## Example request:

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

  url = "https://api.enkryptai.com/guardrails/detect"

  payload = json.dumps({
      "text": "Aluminum alloys can have very high strength-to-weight ratios, making them useful for applications where weight is a critical factor, such as in the aerospace industry",
      "detectors": {
          "topic_detector": {
              "enabled": True,
              "topic": ["science"],
              "block_message": "Your custom message"
          }
      }
  })

  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)

  guardrails_config = GuardrailsConfig.topic(topics=["science"])

  prompt = "Aluminum alloys can have very high strength-to-weight ratios, making them useful for applications where weight is a critical factor, such as in the aerospace industry"

  detect_response = guardrails_client.detect(text=prompt, guardrails_config=guardrails_config)

  print(detect_response)

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

## Example response:

```json JSON theme={"system"}
{
  "summary": {
    "on_topic": 1
  },
  "details": {
    "topic_detector": {
      "science": 0.9998229146003723
    }
  },
  "result_message": "Your custom message"
}
```
