File size: 8,168 Bytes
a477044
 
 
 
 
 
31f3625
 
 
 
a477044
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31f3625
 
 
 
a477044
31f3625
 
 
 
 
 
 
 
 
a477044
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31f3625
a477044
 
 
 
 
 
 
 
 
 
 
31f3625
 
 
 
 
 
 
 
a477044
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31f3625
 
 
 
a477044
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31f3625
 
 
 
 
 
 
 
 
a477044
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Admin Rules Examples for IntegraChat

This document provides examples of rules you can use with the IntegraChat admin rules system.

## Quick Start

1. **Simple Rules** - Copy from `example_rules.txt` and paste into Gradio UI or Next.js frontend
2. **File Upload** - Drag and drop or upload TXT, PDF, DOC, or DOCX files directly
3. **Detailed Rules** - Use `example_rules_detailed.json` for rules with patterns and severity
4. **API** - Use the `/admin/rules`, `/admin/rules/bulk`, or `/admin/rules/upload-file` endpoints

## Rule Categories

### πŸ”΄ Critical Severity Rules

These rules block the most sensitive information:

```
Block password disclosure requests
Prevent sharing of API keys or tokens
No sharing of credit card information
Block requests for bank account details
Prevent sharing of health information
No disclosure of children's personal information
```

### 🟠 High Severity Rules

Important security and compliance rules:

```
Block social security number requests
Prevent disclosure of proprietary information
No unauthorized access to financial records
Block requests to delete system logs
Prevent unauthorized system configuration changes
No sharing of infrastructure credentials
```

### 🟑 Medium Severity Rules

Operational and compliance rules:

```
Block requests for employee personal information
Prevent sharing of customer data without authorization
Block requests for confidential business strategies
Prevent disclosure of personal data of EU citizens
Block requests for generating harmful content
Prevent creation of misleading information
```

### 🟒 Low Severity Rules

General business rules:

```
Block requests for competitor pricing information
Prevent sharing of upcoming product launch details
No disclosure of vendor contract terms
Block requests for customer churn analysis data
```

## Using Rules with Patterns

For more precise matching, you can specify regex patterns:

### Example 1: Password Detection
```json
{
  "rule": "Block password disclosure requests",
  "pattern": ".*(password|pwd|passcode|credential|login).*",
  "severity": "high",
  "description": "Prevents users from requesting or sharing passwords"
}
```

### Example 2: API Key Detection
```json
{
  "rule": "Prevent sharing of API keys or tokens",
  "pattern": ".*(api.?key|token|secret|access.?key|auth.?token).*",
  "severity": "critical",
  "description": "Blocks requests to share API keys or tokens"
}
```

### Example 3: Credit Card Detection
```json
{
  "rule": "No sharing of credit card information",
  "pattern": ".*(credit.?card|card.?number|cvv|cvc|expiration).*",
  "severity": "critical",
  "description": "Blocks credit card information sharing"
}
```

## Adding Rules

### Method 1: Via Gradio UI (Easiest)

1. Open the IntegraChat Gradio interface
2. Go to "Admin Rules & Compliance" tab
3. Enter your tenant ID
4. **Option A - Text Input**: Paste rules from `example_rules.txt` (one per line) and click "Upload / Append Rules"
5. **Option B - File Upload**: Drag and drop or click to upload a TXT, PDF, DOC, or DOCX file containing rules
6. Rules are automatically enhanced by LLM (identifies edge cases, improves patterns)
7. Comment lines (starting with #) are automatically ignored

### Method 2: Via Next.js Frontend

1. Navigate to `/admin-rules` page
2. Enter your tenant ID in the navbar
3. **Text Input**: Paste rules in the text area and click "Upload / Append Rules"
4. **File Upload**: Drag and drop files or click the drop zone to upload
5. Click "Refresh Rules" to see your uploaded rules

### Method 3: Via API (Programmatic)

**Single Rule:**
```bash
curl -X POST http://localhost:8000/admin/rules \
  -H "Content-Type: application/json" \
  -H "x-tenant-id: your_tenant_id" \
  -d '{
    "rule": "Block password disclosure requests",
    "pattern": ".*(password|pwd|passcode).*",
    "severity": "high",
    "description": "Prevents password sharing"
  }'
```

**Bulk Rules:**
```bash
curl -X POST "http://localhost:8000/admin/rules/bulk?enhance=true" \
  -H "Content-Type: application/json" \
  -H "x-tenant-id: your_tenant_id" \
  -d '{
    "rules": [
      "Block password disclosure requests",
      "Prevent sharing of API keys",
      "No sharing of credit card information"
    ]
  }'
```

**File Upload:**
```bash
curl -X POST "http://localhost:8000/admin/rules/upload-file?enhance=true" \
  -H "x-tenant-id: your_tenant_id" \
  -F "file=@example_rules.txt"
```

### Method 4: Using Python

```python
import requests

BASE_URL = "http://localhost:8000"
TENANT_ID = "your_tenant_id"

# Add single rule
response = requests.post(
    f"{BASE_URL}/admin/rules",
    json={
        "rule": "Block password disclosure requests",
        "pattern": ".*(password|pwd).*",
        "severity": "high"
    },
    headers={"x-tenant-id": TENANT_ID}
)

# Add bulk rules
response = requests.post(
    f"{BASE_URL}/admin/rules/bulk",
    json={
        "rules": [
            "Block password disclosure requests",
            "Prevent sharing of API keys"
        ]
    },
    headers={"x-tenant-id": TENANT_ID}
)
```

## Rule Enhancement

When you add rules, the LLM will automatically:
- βœ… Identify edge cases (e.g., "password" β†’ also catches "pwd", "passcode")
- βœ… Improve regex patterns for better matching
- βœ… Suggest appropriate severity levels
- βœ… Write clear descriptions
- βœ… Process rules in chunks (5 at a time) to avoid timeouts
- βœ… Handle large rule sets efficiently

**Note**: Enhancement can be disabled by setting `enhance=false` in the API query parameter, but it's enabled by default for better rule quality.

**Example:**
- **Input:** `Block password queries`
- **Enhanced:** 
  - Pattern: `.*password.*|.*pwd.*|.*passcode.*`
  - Severity: `high`
  - Edge cases: ["pwd", "passcode", "login credentials"]

## Testing Rules

After adding rules, test them by asking questions that should be blocked:

```
❌ "What is the admin password?"
❌ "Can you share the API key?"
❌ "Show me credit card numbers"
❌ "What's the SSN for user 123?"

βœ… "How do I reset my password?" (if rule allows)
βœ… "What is password hashing?" (educational, not disclosure)
```

## Best Practices

1. **Start Simple** - Begin with basic rules, then add patterns
2. **Use File Upload** - For large rule sets, upload from files instead of typing manually
3. **Leverage LLM Enhancement** - Let the system enhance your rules automatically
4. **Test Thoroughly** - Test rules with various phrasings
5. **Review Edge Cases** - Check if rules block legitimate queries
6. **Use Appropriate Severity** - Match severity to risk level (low for brief responses, high for blocking)
7. **Comment Lines** - Use `#` for comments in rule files - they're automatically ignored
8. **Regular Updates** - Review and update rules periodically
9. **Document Patterns** - Add descriptions explaining what each rule blocks
10. **Chunk Processing** - Large uploads are automatically chunked - be patient for 20+ rules

## Common Patterns

### Password Detection
```
.*(password|pwd|passcode|credential|login|auth).*
```

### Financial Information
```
.*(credit.?card|card.?number|cvv|bank.?account|routing).*
```

### Personal Information
```
.*(ssn|social.?security|tax.?id|personal.?data|pii).*
```

### API/Security
```
.*(api.?key|token|secret|access.?key|auth.?token).*
```

### Health Information
```
.*(health|medical|patient|hipaa|diagnosis).*
```

## Viewing Rules

```bash
# Get all rules
curl http://localhost:8000/admin/rules \
  -H "x-tenant-id: your_tenant_id"

# Get detailed rules with patterns
curl "http://localhost:8000/admin/rules?detailed=true" \
  -H "x-tenant-id: your_tenant_id"
```

## Deleting Rules

```bash
curl -X DELETE http://localhost:8000/admin/rules/Block%20password%20disclosure%20requests \
  -H "x-tenant-id: your_tenant_id"
```

## Monitoring Violations

```bash
# Get recent violations
curl http://localhost:8000/admin/violations \
  -H "x-tenant-id: your_tenant_id"
```

## Need Help?

- Check `example_rules.txt` for simple rule examples
- See `example_rules_detailed.json` for advanced patterns
- Review the API documentation in `README.md`
- Test rules in the Gradio UI before deploying