API Reference

Check text for vulnerabilities. Input body in the form of string. Avg latency <200 ms.

Example: Checking for an injection inside of text/unstructured data

def content_contains_attack(content : str) -> bool:
  url = "https://api.promptarmor.com/v1/check_content"
  
  headers = {
      "accept": "application/json; charset=utf-8",
      "content-type": "application/json",
      #You should store your API key in an environment variable
      "Api-Key": "Your-Api-Key"
  }
    
  #Call the PromptArmor endpoint
  contains_attack = requests.post(url,  data=content, headers=headers).json()["containsInjection"]
  
  return contains_attack

Implementation Example: Chatbot

def process_user_message(user_message: str) -> str:
  
  if content_contains_injection(message):
    return "Please don't use injections! Try another message."
  
  #If there isn't an injection, continue with the response logic
  chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": user_message}])
  
  return chat_completion

Implementation Example: Agents

def process_external_data(data: str):
  
  if content_contains_injection(data):
    print("Injection found in data!")
    #Handle the injection case(e.g. skip processing the file
    ...
  
  #No injection, continue with the agent action
  do_agent_action_on_data(data)