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

# Create your own Detectors

> Learn how to make custom Detectors

Dome makes it easy to create and define your own detection methods to use in Guardrails that can execute custom logic to protect your agents. To create a custom Detector, you need to register it to a category with a name. The example below showcases how to make a custom Detector that checks to see if the input string is within a minimum and maximum length.

<CodeGroup>
  ```python title="Python" icon="python" theme={null}
  from vijil_dome.Detectors import (
      DetectionCategory,
      DetectionResult,
      DetectionMethod,
      register_method,
  )

  # Custom logic - block queries that are under a minimum number of characters or over a maximum number of characters
  CUSTOM_LENGTH_DETECTOR = "custom-length-Detector"


  # You must register the detection method with one of five categories - Security, Moderation, Privacy, Integrity or Generic
  @register_method(DetectionCategory.Security, CUSTOM_LENGTH_DETECTOR)
  class CustomLengthDetector(DetectionMethod):
      def __init__(self,
                   min_length = 10,
                   max_length = 1000):
          super().__init__()
          self.min_length = min_length
          self.max_length = max_length

      # The detection method must be async, and must produce a DetectionResult
      async def detect(self, query_string: str) -> DetectionResult:
          flagged = len(query_string) < min_length or len(query_string) > max_length

          # The detection result is a tuple comprising of a boolean and a dictionary
          # The dictionary can contain any metadata you wish to record. We HIGHLY recommend including the original query string, type and response string
          return flagged, {
              "type": type(self),
              "length": len(query_string),
              "query_string": query_string,
              "response_string": self.blocked_response_string
              if flagged
              else response_string,
          }
  ```
</CodeGroup>

You can now use `custom-length-detector` in your Dome configuration.

<Warning>
  Make sure you define your custom detection logic before you instantiate your configuration. Alternatively, you can define it in another file and import the class before loading your config. This is to ensure that the `register_method` decorator can register your Detector before it gets used.
</Warning>
