Skip to main content
POST
/
ai
/
session-analyzer
/
rules
Create AI Session Analyzer Rule
curl --request POST \
  --url https://use.hoop.dev/api/ai/session-analyzer/rules \
  --header 'Content-Type: application/json' \
  --data '
{
  "connection_names": [
    "pgdemo",
    "mysql-prod"
  ],
  "name": "block-dangerous-queries",
  "risk_evaluation": {
    "high_risk_action": "block_execution",
    "low_risk_action": "allow_execution",
    "medium_risk_action": "allow_execution"
  },
  "custom_prompt": "Treat any query that touches the payments schema as high risk.",
  "description": "Blocks high-risk SQL commands"
}
'
import requests

url = "https://use.hoop.dev/api/ai/session-analyzer/rules"

payload = {
"connection_names": ["pgdemo", "mysql-prod"],
"name": "block-dangerous-queries",
"risk_evaluation": {
"high_risk_action": "block_execution",
"low_risk_action": "allow_execution",
"medium_risk_action": "allow_execution"
},
"custom_prompt": "Treat any query that touches the payments schema as high risk.",
"description": "Blocks high-risk SQL commands"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
connection_names: ['pgdemo', 'mysql-prod'],
name: 'block-dangerous-queries',
risk_evaluation: {
high_risk_action: 'block_execution',
low_risk_action: 'allow_execution',
medium_risk_action: 'allow_execution'
},
custom_prompt: 'Treat any query that touches the payments schema as high risk.',
description: 'Blocks high-risk SQL commands'
})
};

fetch('https://use.hoop.dev/api/ai/session-analyzer/rules', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://use.hoop.dev/api/ai/session-analyzer/rules",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'connection_names' => [
'pgdemo',
'mysql-prod'
],
'name' => 'block-dangerous-queries',
'risk_evaluation' => [
'high_risk_action' => 'block_execution',
'low_risk_action' => 'allow_execution',
'medium_risk_action' => 'allow_execution'
],
'custom_prompt' => 'Treat any query that touches the payments schema as high risk.',
'description' => 'Blocks high-risk SQL commands'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://use.hoop.dev/api/ai/session-analyzer/rules"

payload := strings.NewReader("{\n \"connection_names\": [\n \"pgdemo\",\n \"mysql-prod\"\n ],\n \"name\": \"block-dangerous-queries\",\n \"risk_evaluation\": {\n \"high_risk_action\": \"block_execution\",\n \"low_risk_action\": \"allow_execution\",\n \"medium_risk_action\": \"allow_execution\"\n },\n \"custom_prompt\": \"Treat any query that touches the payments schema as high risk.\",\n \"description\": \"Blocks high-risk SQL commands\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://use.hoop.dev/api/ai/session-analyzer/rules")
.header("Content-Type", "application/json")
.body("{\n \"connection_names\": [\n \"pgdemo\",\n \"mysql-prod\"\n ],\n \"name\": \"block-dangerous-queries\",\n \"risk_evaluation\": {\n \"high_risk_action\": \"block_execution\",\n \"low_risk_action\": \"allow_execution\",\n \"medium_risk_action\": \"allow_execution\"\n },\n \"custom_prompt\": \"Treat any query that touches the payments schema as high risk.\",\n \"description\": \"Blocks high-risk SQL commands\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://use.hoop.dev/api/ai/session-analyzer/rules")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"connection_names\": [\n \"pgdemo\",\n \"mysql-prod\"\n ],\n \"name\": \"block-dangerous-queries\",\n \"risk_evaluation\": {\n \"high_risk_action\": \"block_execution\",\n \"low_risk_action\": \"allow_execution\",\n \"medium_risk_action\": \"allow_execution\"\n },\n \"custom_prompt\": \"Treat any query that touches the payments schema as high risk.\",\n \"description\": \"Blocks high-risk SQL commands\"\n}"

response = http.request(request)
puts response.read_body
{
  "connection_names": [
    "pgdemo",
    "mysql-prod"
  ],
  "created_at": "2024-07-25T15:56:35.317601Z",
  "custom_prompt": "Treat any query that touches the payments schema as high risk.",
  "description": "Blocks high-risk SQL commands",
  "id": "15B5A2FD-0706-4A47-B1CF-B93CCFC5B3D7",
  "name": "block-dangerous-queries",
  "risk_evaluation": {
    "high_risk": {
      "action": "require_access_request",
      "access_request_rule_name": "prod-approvals"
    },
    "high_risk_action": "block_execution",
    "low_risk": {
      "action": "require_access_request",
      "access_request_rule_name": "prod-approvals"
    },
    "low_risk_action": "allow_execution",
    "medium_risk": {
      "action": "require_access_request",
      "access_request_rule_name": "prod-approvals"
    },
    "medium_risk_action": "allow_execution"
  },
  "updated_at": "2024-07-25T15:56:35.317601Z"
}
{
"message": "the error description"
}
{
"message": "the error description"
}
{
"message": "the error description"
}

Body

application/json

The request body resource

connection_names
string[]
required

Connection names this rule applies to

Example:
["pgdemo", "mysql-prod"]
name
string
required

Unique name for the rule

Example:

"block-dangerous-queries"

risk_evaluation
object
required

Risk evaluation actions per level

custom_prompt
string

Optional extra instructions appended to the default system prompt

Example:

"Treat any query that touches the payments schema as high risk."

description
string

Optional description

Example:

"Blocks high-risk SQL commands"

Response

Created

connection_names
string[]

Connection names this rule applies to

Example:
["pgdemo", "mysql-prod"]
created_at
string
read-only

The time the resource was created

Example:

"2024-07-25T15:56:35.317601Z"

custom_prompt
string

Optional extra instructions appended to the default system prompt

Example:

"Treat any query that touches the payments schema as high risk."

description
string

Optional description

Example:

"Blocks high-risk SQL commands"

id
string<uuid>
read-only

The resource identifier

Example:

"15B5A2FD-0706-4A47-B1CF-B93CCFC5B3D7"

name
string

Unique name for the rule

Example:

"block-dangerous-queries"

risk_evaluation
object

Risk evaluation actions per level

updated_at
string
read-only

The time the resource was updated

Example:

"2024-07-25T15:56:35.317601Z"