Skip to content

Commit 028a738

Browse files
Merge branch 'trustyai-explainability:main' into generation-detection
2 parents a92aa95 + 72fd63a commit 028a738

File tree

12 files changed

+676
-239
lines changed

12 files changed

+676
-239
lines changed

.github/workflows/build-and-push.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,27 @@ jobs:
5454
echo "SHA: ${{ github.event.pull_request.head.sha }}"
5555
echo "MAIN IMAGE AT: ${{ vars.QUAY_RELEASE_REPO }}:latest"
5656
echo "CI IMAGE AT: quay.io/trustyai/guardrails-detector-huggingface-runtime-ci:${{ github.event.pull_request.head.sha }}"
57-
echo "Built-In Detector CI IMAGE AT: quay.io/trustyai/builtin-detector-ci:${{ github.event.pull_request.head.sha }}"
57+
echo "Built-In Detector CI IMAGE AT: quay.io/trustyai/guardrails-detector-built-in-ci:${{ github.event.pull_request.head.sha }}"
5858
5959
# Set environments depending on context
6060
- name: Set CI environment
6161
if: env.BUILD_CONTEXT == 'ci'
6262
run: |
6363
echo "TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
6464
echo "IMAGE_NAME=quay.io/trustyai/guardrails-detector-huggingface-runtime-ci" >> $GITHUB_ENV
65-
echo "BUILTIN_IMAGE_NAME=quay.io/trustyai/builtin-detector-ci" >> $GITHUB_ENV
65+
echo "BUILTIN_IMAGE_NAME=quay.io/trustyai/guardrails-detector-built-in-ci" >> $GITHUB_ENV
6666
- name: Set main-branch environment
6767
if: env.BUILD_CONTEXT == 'main'
6868
run: |
6969
echo "TAG=latest" >> $GITHUB_ENV
7070
echo "IMAGE_NAME=${{ vars.QUAY_RELEASE_REPO }}" >> $GITHUB_ENV
71-
echo "BUILTIN_IMAGE_NAME=quay.io/trustyai/builtin-detector" >> $GITHUB_ENV
71+
echo "BUILTIN_IMAGE_NAME=quay.io/trustyai/guardrails-detector-built-in" >> $GITHUB_ENV
7272
- name: Set tag environment
7373
if: env.BUILD_CONTEXT == 'tag'
7474
run: |
7575
echo "TAG=${{ github.ref_name }}" >> $GITHUB_ENV
7676
echo "IMAGE_NAME=${{ vars.QUAY_RELEASE_REPO }}" >> $GITHUB_ENV
77-
echo "BUILTIN_IMAGE_NAME=quay.io/trustyai/builtin-detector" >> $GITHUB_ENV
77+
echo "BUILTIN_IMAGE_NAME=quay.io/trustyai/guardrails-detector-built-in" >> $GITHUB_ENV
7878
#
7979
# Run docker commands
8080
- name: Put expiry date on CI-tagged image
@@ -113,7 +113,7 @@ jobs:
113113
PR image build completed successfully!
114114
115115
📦 [PR image](https://quay.io/repository/trustyai/guardrails-detector-huggingface-runtime-ci?tab=tags): `quay.io/trustyai/guardrails-detector-huggingface-runtime-ci:${{ github.event.pull_request.head.sha }}`
116-
📦 [PR image](https://quay.io/trustyai/builtin-detector-ci?tab=tags): `quay.io/trustyai/builtin-detector-ci:${{ github.event.pull_request.head.sha }}`
116+
📦 [PR image](https://quay.io/trustyai/guardrails-detector-built-in-ci?tab=tags): `quay.io/trustyai/guardrails-detector-built-in-ci:${{ github.event.pull_request.head.sha }}`
117117
- name: Trivy scan
118118
uses: aquasecurity/[email protected]
119119
with:
@@ -136,11 +136,13 @@ jobs:
136136
exit-code: '0'
137137
ignore-unfixed: false
138138
vuln-type: 'os,library'
139-
- name: Update Security tab
139+
- name: Update Security tab - Huggingface
140140
uses: github/codeql-action/upload-sarif@v3
141141
with:
142142
sarif_file: 'trivy-results.sarif'
143-
- name: Update Security tab
143+
category: huggingface
144+
- name: Update Security tab - Built-in
144145
uses: github/codeql-action/upload-sarif@v3
145146
with:
146147
sarif_file: 'trivy-results-built-in.sarif'
148+
category: built-in

README.md

Lines changed: 26 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -17,123 +17,37 @@ At the moment, the following detectors are supported:
1717

1818
## Building
1919

20-
* `huggingface`: podman build -f detectors/Dockerfile.hf detectors
21-
* `llm_judge`: podman build -f detectors/Dockerfile.llm_judge detectors
22-
* `builtIn`: podman build -f detectors/Dockerfile.builtIn detectors
20+
To build the detector images, use the following commands:
21+
22+
| Detector | Build Command |
23+
|----------|---------------|
24+
| `huggingface` | `podman build -t $TAG -f detectors/Dockerfile.hf detectors` |
25+
| `llm_judge` | `podman build -t $TAG -f detectors/Dockerfile.judge detectors` |
26+
| `builtIn` | `podman build -t $TAG -f detectors/Dockerfile.builtIn detectors` |
27+
28+
Replace `$TAG` with your desired image tag (e.g., `my-detector:latest`).
29+
2330

2431
## Running locally
25-
* `builtIn`: podman run -p 8080:8080 $BUILT_IN_IMAGE
26-
27-
### File Type Validation Example
28-
```bash
29-
curl -X POST http://localhost:8080/api/v1/text/contents \
30-
-H "Content-Type: application/json" \
31-
-d '{
32-
"contents": [
33-
"{\"hello\": \"message\"}",
34-
"not valid json"
35-
],
36-
"detector_params": {
37-
"file_type": [
38-
"json"
39-
]
40-
}
41-
}'
42-
```
43-
Response:
44-
```json
45-
[
46-
[],
47-
[
48-
{
49-
"start": 0,
50-
"end": 14,
51-
"text": "not valid json",
52-
"detection": "invalid_json",
53-
"detection_type": "file_type",
54-
"score": 1.0,
55-
"evidences": null
56-
}
57-
]
58-
]
59-
```
60-
61-
### PII Validation Example
62-
```bash
63-
curl -X POST http://localhost:8080/api/v1/text/contents \
64-
-H "Content-Type: application/json" \
65-
-d '{
66-
"contents": [
67-
"Hi my email is [email protected]",
68-
"There is a party@my house and you can reach me at 123-456-7890"
69-
],
70-
"detector_params": {
71-
"regex": [
72-
"email", "us-phone-number"
73-
]
74-
}
75-
}' | jq
76-
```
77-
Response:
78-
```json
79-
[
80-
[
81-
{
82-
"start": 15,
83-
"end": 26,
84-
"text": "[email protected]",
85-
"detection": "email_address",
86-
"detection_type": "pii",
87-
"score": 1.0,
88-
"evidences": null
89-
}
90-
],
91-
[
92-
{
93-
"start": 50,
94-
"end": 62,
95-
"text": "123-456-7890",
96-
"detection": "us-phone-number",
97-
"detection_type": "pii",
98-
"score": 1.0,
99-
"evidences": null
100-
}
101-
]
102-
]
103-
```
104-
105-
### Get list of built-in detection algorithms:
106-
```bash
107-
curl http://localhost:8080/registry | jq
108-
```
109-
Response:
110-
```json
111-
{
112-
"regex": {
113-
"credit-card": "Detect credit cards in the text contents (Visa, MasterCard, Amex, Discover, Diners Club, JCB) with Luhn check",
114-
"email": "Detect email addresses in the text contents",
115-
"ipv4": "Detect IPv4 addresses in the text contents",
116-
"ipv6": "Detect IPv6 addresses in the text contents",
117-
"us-phone-number": "Detect US phone numbers in the text contents",
118-
"us-social-security-number": "Detect social security numbers in the text contents",
119-
"uk-post-code": "Detect UK post codes in the text contents",
120-
"$CUSTOM_REGEX": "Replace $CUSTOM_REGEX with a custom regex to define your own regex detector"
121-
},
122-
"file_type": {
123-
"json": "Detect if the text contents is not valid JSON",
124-
"xml": "Detect if the text contents is not valid XML",
125-
"yaml": "Detect if the text contents is not valid YAML",
126-
"json-with-schema:$SCHEMA": "Detect if the text contents does not satisfy a provided JSON schema. To specify a schema, replace $SCHEMA with a JSON schema.",
127-
"xml-with-schema:$SCHEMA": "Detect if the text contents does not satisfy a provided XML schema. To specify a schema, replace $SCHEMA with an XML Schema Definition (XSD)",
128-
"yaml-with-schema:$SCHEMA": "Detect if the text contents does not satisfy a provided schema. To specify a schema, replace $SCHEMA with a JSON schema. That's not a typo, you validate YAML with a JSON schema!"
129-
}
130-
}
131-
132-
```
32+
33+
### Quick Start Commands
34+
35+
| Detector | Run Command | Notes |
36+
|----------|-------------|-------|
37+
| `builtIn` | `podman run -p 8080:8080 $BUILT_IN_IMAGE` | Ready to use |
38+
| `huggingface` | `podman run -p 8000:8000 -e MODEL_DIR=/mnt/models/$MODEL_NAME -v $MODEL_PATH:/mnt/models/$MODEL_NAME:Z $HF_IMAGE` | Requires model download |
39+
| `llm_judge` | `podman run -p 8000:8000 -e VLLM_BASE_URL=$LLM_SERVER_URL $LLM_JUDGE_IMAGE` | Requires OpenAI-compatible LLM server |
40+
41+
42+
### Detailed Setup Instructions & Examples
43+
44+
- **Built-in detector**: No additional setup required. Check out [built-in detector examples](docs/builtin_examples.md) to see how to use the built-in detectors for file type validation and personally identifiable information (PII) detection
45+
- **Hugging Face detector**: Check out [Hugging Face detector examples](docs/hf_examples.md) for a complete setup and examples on how to use the Hugging Face detectors for detecting toxic content and prompt injection
46+
- **LLM Judge detector**: Check out [LLM Judge detector examples](docs/llm_judge_examples.md) for a complete setup and examples on how to use any OpenAI API compatible LLM for content assessment with built-in metrics and custom natural-language criteria
13347

13448
## API
13549
See [IBM Detector API](https://foundation-model-stack.github.io/fms-guardrails-orchestrator/?urls.primaryName=Detector+API)
13650

13751
## License
13852

139-
This project is licensed under the Apache License Version 2.0 - see the [LICENSE](./LICENSE) file for details.
53+
This project is licensed under the Apache License Version 2.0 - see the [LICENSE](./LICENSE) file for details.

detectors/Dockerfile.builtIn

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ COPY ./common /app/detectors/common
2323
COPY ./built_in/* /app
2424

2525
EXPOSE 8080
26-
CMD ["uvicorn", "app:app", "--workers", "4", "--host", "0.0.0.0", "--port", "8080", "--log-config", "/app/detectors/common/log_conf.yaml"]
26+
27+
# for backwards compatibility with existing k8s deployment configs
28+
RUN mkdir /app/bin &&\
29+
echo '#!/bin/bash' > /app/bin/regex-detector &&\
30+
echo "uvicorn app:app --workers 4 --host 0.0.0.0 --port 8080 --log-config /app/detectors/common/log_conf.yaml" >> /app/bin/regex-detector &&\
31+
chmod +x /app/bin/regex-detector
32+
CMD ["/app/bin/regex-detector"]

detectors/Dockerfile.hf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ RUN echo "$CACHEBUST"
2323
COPY ./common /common
2424
COPY ./huggingface/app.py /app
2525
COPY ./huggingface/detector.py /app
26-
COPY ./huggingface/scheme.py /app
2726

2827
EXPOSE 8000
2928
CMD ["uvicorn", "app:app", "--workers", "4", "--host", "0.0.0.0", "--port", "8000", "--log-config", "/common/log_conf.yaml"]

detectors/huggingface/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from common.app import DetectorBaseAPI as FastAPI
1111
from detector import Detector
12-
from scheme import (
12+
from common.scheme import (
1313
ContentAnalysisHttpRequest,
1414
ContentsAnalysisResponse,
1515
Error,

0 commit comments

Comments
 (0)