Skip to content

Commit 7bb8bc0

Browse files
authored
CI job for linting and resolve lint issues / PR 7
Add CI job to run lint (tests will come later) and resolve lint issues
2 parents 7bdf8a9 + de07ac2 commit 7bb8bc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+721
-670
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
lint-and-test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: ["3.11", "3.12", "3.13"]
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Set up uv
24+
uses: astral-sh/setup-uv@v4
25+
with:
26+
enable-cache: true
27+
cache-dependency-glob: |
28+
uv.lock
29+
pyproject.toml
30+
31+
- name: Install dependencies
32+
run: make sync
33+
34+
- name: Lint with ruff
35+
run: make lint
36+
37+
# TODO: enable this once all the tests pass
38+
# - name: Run tests
39+
# run: make tests

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For full details, advanced usage, and API reference, see here: [OpenAI Guardrail
1717
2. **Install dependencies**
1818
- **Install from this repo:**
1919
```bash
20-
pip install -e .[presidio]
20+
pip install -e '.[presidio]'
2121
```
2222
- **Eventually this will be:**
2323
```bash

examples/basic/azure_implementation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
import asyncio
1010
import os
11+
12+
from dotenv import load_dotenv
1113
from openai import BadRequestError
14+
1215
from guardrails import (
1316
GuardrailsAsyncAzureOpenAI,
1417
GuardrailTripwireTriggered,
1518
)
16-
from dotenv import load_dotenv
1719

1820
load_dotenv()
1921

@@ -72,14 +74,14 @@ async def process_input(
7274
except GuardrailTripwireTriggered as e:
7375
# Extract information from the triggered guardrail
7476
triggered_result = e.guardrail_result
75-
print(f" Input blocked. Please try a different message.")
77+
print(" Input blocked. Please try a different message.")
7678
print(f" Full result: {triggered_result}")
7779
raise
7880
except BadRequestError as e:
7981
# Handle Azure's built-in content filter errors
8082
# Will be triggered not when the guardrail is tripped, but when the LLM is filtered by Azure.
8183
if "content_filter" in str(e):
82-
print(f"\n🚨 Third party content filter triggered during LLM call.")
84+
print("\n🚨 Third party content filter triggered during LLM call.")
8385
print(f" Error: {e}")
8486
raise
8587
else:

examples/basic/custom_context.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from guardrails import GuardrailsAsyncOpenAI, GuardrailTripwireTriggered
1212
from guardrails.context import GuardrailsContext, set_context
1313

14-
1514
# Pipeline config with an LLM-based guardrail using Gemma3 via Ollama
1615
PIPELINE_CONFIG = {
1716
"version": 1,

examples/basic/hello_world.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
from contextlib import suppress
5+
56
from rich.console import Console
67
from rich.panel import Panel
78

@@ -55,7 +56,7 @@ async def process_input(
5556

5657
return response.llm_response.id
5758

58-
except GuardrailTripwireTriggered as exc:
59+
except GuardrailTripwireTriggered:
5960
raise
6061

6162

examples/basic/local_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import asyncio
44
from contextlib import suppress
5-
from rich.console import Console
6-
from rich.panel import Panel
75

86
from openai.types.chat import ChatCompletionMessageParam
7+
from rich.console import Console
8+
from rich.panel import Panel
99

1010
from guardrails import GuardrailsAsyncOpenAI, GuardrailTripwireTriggered
1111

@@ -55,7 +55,7 @@ async def process_input(
5555
input_data.append({"role": "user", "content": user_input})
5656
input_data.append({"role": "assistant", "content": response_content})
5757

58-
except GuardrailTripwireTriggered as exc:
58+
except GuardrailTripwireTriggered:
5959
# Handle guardrail violations
6060
raise
6161

examples/basic/multi_bundle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from rich.console import Console
77
from rich.live import Live
88
from rich.panel import Panel
9+
910
from guardrails import GuardrailsAsyncOpenAI, GuardrailTripwireTriggered
1011

1112
console = Console()
@@ -79,7 +80,7 @@ async def process_input(
7980

8081
return response_id_to_return
8182

82-
except GuardrailTripwireTriggered as exc:
83+
except GuardrailTripwireTriggered:
8384
# Clear the live display when output guardrail is triggered
8485
live.update("")
8586
console.clear()

examples/basic/multiturn_chat_with_alignment.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
from __future__ import annotations
2020

2121
import argparse
22-
import json
23-
from typing import Iterable
2422
import asyncio
23+
import json
24+
from collections.abc import Iterable
2525

2626
from rich.console import Console
2727
from rich.panel import Panel
@@ -177,10 +177,10 @@ def _stage_lines(stage_name: str, stage_results: Iterable) -> list[str]:
177177
# Add interpretation
178178
if r.tripwire_triggered:
179179
lines.append(
180-
f" ⚠️ PROMPT INJECTION DETECTED: Action does not serve user's goal!"
180+
" ⚠️ PROMPT INJECTION DETECTED: Action does not serve user's goal!"
181181
)
182182
else:
183-
lines.append(f" ✨ ALIGNED: Action serves user's goal")
183+
lines.append(" ✨ ALIGNED: Action serves user's goal")
184184
else:
185185
# Other guardrails - show basic info
186186
for key, value in info.items():

examples/basic/pii_mask_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import asyncio
1313
from contextlib import suppress
14+
1415
from rich.console import Console
1516
from rich.panel import Panel
1617

examples/basic/structured_outputs_example.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Simple example demonstrating structured outputs with GuardrailsClient."""
22

33
import asyncio
4+
45
from pydantic import BaseModel, Field
56

67
from guardrails import GuardrailsAsyncOpenAI, GuardrailTripwireTriggered
@@ -37,13 +38,13 @@ async def extract_user_info(guardrails_client: GuardrailsAsyncOpenAI, text: str)
3738
model="gpt-4.1-nano",
3839
text_format=UserInfo
3940
)
40-
41+
4142
# Access the parsed structured output
4243
user_info = response.llm_response.output_parsed
4344
print(f"✅ Successfully extracted: {user_info.name}, {user_info.age}, {user_info.email}")
44-
45+
4546
return user_info
46-
47+
4748
except GuardrailTripwireTriggered as exc:
4849
print(f"❌ Guardrail triggered: {exc}")
4950
raise
@@ -75,4 +76,4 @@ async def main() -> None:
7576

7677

7778
if __name__ == "__main__":
78-
asyncio.run(main())
79+
asyncio.run(main())

0 commit comments

Comments
 (0)