Skip to content

Commit 49cfc6a

Browse files
committed
Move attribution section before Use Cases and remove detailed methods documentation
1 parent ef2fe5b commit 49cfc6a

1 file changed

Lines changed: 2 additions & 127 deletions

File tree

README.md

Lines changed: 2 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ More info can be found on the [Llama Guard 4 12B](https://huggingface.co/meta-ll
7777

7878
---
7979

80+
81+
8082
## Use Cases & Security Scenarios
8183

8284
Pytector works best in scenarios where you need immediate security controls beyond what foundation models provide by default:
@@ -288,134 +290,7 @@ is_blocked, matched = detector.check_input_keywords(test_prompt)
288290
print(f"Blocked: {is_blocked}, Keywords: {matched}")
289291
```
290292

291-
---
292-
293-
## Methods
294-
295-
### `__init__(self, model_name_or_url="deberta", default_threshold=0.5, use_groq=False, api_key=None, groq_model="meta-llama/llama-guard-4-12b", enable_keyword_blocking=False, input_keywords=None, output_keywords=None, case_sensitive=False, input_block_message=None, output_block_message=None, keyword_block_hazard_code=None)`
296-
297-
Initializes a new instance of the `PromptInjectionDetector`.
298-
299-
- `model_name_or_url`: A string specifying the model. Can be a predefined key (`deberta`, `distilbert`), a Hugging Face model ID/URL, or a local path to a `.gguf` file.
300-
- `default_threshold`: Probability threshold for Hugging Face models.
301-
- `use_groq`: Set to `True` to enable Groq's API.
302-
- `api_key`: Required if `use_groq=True`.
303-
- `groq_model`: The specific model to use with the Groq API (default: `meta-llama/llama-guard-4-12b`).
304-
- `enable_keyword_blocking`: Set to `True` to enable keyword-based blocking (default: `False`).
305-
- `input_keywords`: Custom list of keywords for input blocking (uses default list if `None` and `enable_keyword_blocking=True`).
306-
- `output_keywords`: Custom list of keywords for output blocking (uses default list if `None` and `enable_keyword_blocking=True`).
307-
- `case_sensitive`: Set to `True` for case-sensitive keyword matching (default: `False`).
308-
- `input_block_message`: Custom message for input blocking (use `{matched_keywords}` placeholder).
309-
- `output_block_message`: Custom message for output blocking (use `{matched_keywords}` placeholder).
310-
- `keyword_block_hazard_code`: Custom hazard code for keyword blocking (default: `"KEYWORD_BLOCK"`).
311-
312-
### `detect_injection(self, prompt, threshold=None)`
313-
314-
Evaluates whether a text prompt is a prompt injection attack using a local model (Hugging Face or GGUF).
315-
316-
- Returns `(is_injected, probability)`. `probability` is `None` for GGUF models.
317-
318-
### `detect_injection_api(self, prompt)`
319-
320-
Uses Groq's API to evaluate a prompt for unsafe content.
321-
322-
- Returns `(is_safe, hazard_code)`. `is_safe` can be `True`, `False`, or `None` (on API error). `hazard_code` can be the specific code (e.g., `S1`), `None` (if safe), `API_ERROR`, or `PARSE_ERROR`.
323-
324-
### `report_injection_status(self, prompt, threshold=None)`
325-
326-
Reports whether a prompt is a potential injection or contains unsafe content, handling different detector types (HF, Groq, GGUF).
327-
328-
### `check_input_keywords(self, prompt)`
329-
330-
Checks if input prompt contains blocked keywords.
331-
332-
- Returns `(is_blocked, matched_keywords)` tuple.
333-
334-
### `check_output_keywords(self, response)`
335-
336-
Checks if output response contains blocked keywords.
337-
338-
- Returns `(is_blocked, matched_keywords)` tuple.
339-
340-
### `check_response_safety(self, response)`
341-
342-
Checks if a response is safe (doesn't contain blocked keywords).
343-
344-
- Returns `(is_safe, matched_keywords)` tuple.
345-
346-
### `add_input_keywords(self, keywords)`
347-
348-
Adds keywords to the input blocking list.
349-
350-
- `keywords`: String or list of keywords to add.
351-
352-
### `add_output_keywords(self, keywords)`
353-
354-
Adds keywords to the output blocking list.
355-
356-
- `keywords`: String or list of keywords to add.
357-
358-
### `remove_input_keywords(self, keywords)`
359293

360-
Removes keywords from the input blocking list.
361-
362-
- `keywords`: String or list of keywords to remove.
363-
364-
### `remove_output_keywords(self, keywords)`
365-
366-
Removes keywords from the output blocking list.
367-
368-
- `keywords`: String or list of keywords to remove.
369-
370-
### `get_input_keywords(self)`
371-
372-
Gets the current list of input blocking keywords.
373-
374-
- Returns a copy of the current input keywords list.
375-
376-
### `get_output_keywords(self)`
377-
378-
Gets the current list of output blocking keywords.
379-
380-
- Returns a copy of the current output keywords list.
381-
382-
### `set_input_block_message(self, message)`
383-
384-
Sets custom message for input blocking.
385-
386-
- `message`: Custom message (use `{matched_keywords}` placeholder).
387-
388-
### `set_output_block_message(self, message)`
389-
390-
Sets custom message for output blocking.
391-
392-
- `message`: Custom message (use `{matched_keywords}` placeholder).
393-
394-
### `set_keyword_block_hazard_code(self, hazard_code)`
395-
396-
Sets custom hazard code for keyword blocking.
397-
398-
- `hazard_code`: Custom hazard code.
399-
400-
### `get_input_block_message(self)`
401-
402-
Gets the current input block message.
403-
404-
- Returns the current input block message.
405-
406-
### `get_output_block_message(self)`
407-
408-
Gets the current output block message.
409-
410-
- Returns the current output block message.
411-
412-
### `get_keyword_block_hazard_code(self)`
413-
414-
Gets the current keyword block hazard code.
415-
416-
- Returns the current keyword block hazard code.
417-
418-
---
419294

420295
## Security Best Practices
421296

0 commit comments

Comments
 (0)