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

# Sponge Attack Detector

This detector identifies potential infinite loops or infinite recursion in the generated text. It helps prevent the model from getting stuck in an infinite loop and causing a denial of service attack.

## Example request:

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

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

  payload = json.dumps({
      "text": "All programmers are men and women can't code.",
      "detectors": {
          "sponge_attack": {
              "enabled": True,
              "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.sponge_attack()

  prompt = "All programmers are men and women can't code."

  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": {
    "sponge_attack": 1
  },
  "details": {
    "sponge_attack": {
      "sponge_attack_detected": true,
      "compliance_mapping": {
        "owasp_llm_2025": [
          "LLM10:2025 Unbounded Consumption"
        ],
        "mitre_atlas": [
          "AML.T0029: Denial of ML Service"
        ],
        "nist_ai_rmf": [
          "MANAGE 4.1 (Resource management & availability)"
        ],
        "eu_ai_act": [
          "Article 15(4) (Cybersecurity & resilience)"
        ],
        "iso_iec_standards": [
          "ISO/IEC 27001: A.12.2 (Protection against malware & resource abuse)"
        ]
      }
    }
  },
  "result_message": "Your custom message"
}
```
