@@ -14,6 +14,11 @@ class Responses:
1414 """Responses API with guardrails (sync)."""
1515
1616 def __init__ (self , client : GuardrailsBaseClient ) -> None :
17+ """Initialize Responses resource.
18+
19+ Args:
20+ client: GuardrailsBaseClient instance with configured guardrails.
21+ """
1722 self ._client = client
1823
1924 def create (
@@ -23,7 +28,7 @@ def create(
2328 stream : bool = False ,
2429 tools : list [dict ] | None = None ,
2530 suppress_tripwire : bool = False ,
26- ** kwargs
31+ ** kwargs ,
2732 ):
2833 """Create response with guardrails (synchronous).
2934
@@ -44,9 +49,7 @@ def create(
4449 )
4550
4651 # Apply pre-flight modifications (PII masking, etc.)
47- modified_input = self ._client ._apply_preflight_modifications (
48- input , preflight_results
49- )
52+ modified_input = self ._client ._apply_preflight_modifications (input , preflight_results )
5053
5154 # Input guardrails and LLM call concurrently
5255 with ThreadPoolExecutor (max_workers = 1 ) as executor :
@@ -83,14 +86,7 @@ def create(
8386 suppress_tripwire = suppress_tripwire ,
8487 )
8588
86- def parse (
87- self ,
88- input : list [dict [str , str ]],
89- model : str ,
90- text_format : type [BaseModel ],
91- suppress_tripwire : bool = False ,
92- ** kwargs
93- ):
89+ def parse (self , input : list [dict [str , str ]], model : str , text_format : type [BaseModel ], suppress_tripwire : bool = False , ** kwargs ):
9490 """Parse response with structured output and guardrails (synchronous)."""
9591 latest_message , _ = self ._client ._extract_latest_user_message (input )
9692
@@ -103,9 +99,7 @@ def parse(
10399 )
104100
105101 # Apply pre-flight modifications (PII masking, etc.)
106- modified_input = self ._client ._apply_preflight_modifications (
107- input , preflight_results
108- )
102+ modified_input = self ._client ._apply_preflight_modifications (input , preflight_results )
109103
110104 # Input guardrails and LLM call concurrently
111105 with ThreadPoolExecutor (max_workers = 1 ) as executor :
@@ -135,26 +129,30 @@ def parse(
135129 def retrieve (self , response_id : str , suppress_tripwire : bool = False , ** kwargs ):
136130 """Retrieve response with output guardrail validation (synchronous)."""
137131 # Get the response using the original OpenAI client
138- response = self ._client ._resource_client .responses .retrieve (
139- response_id , ** kwargs
140- )
132+ response = self ._client ._resource_client .responses .retrieve (response_id , ** kwargs )
141133
142134 # Run output guardrails on the retrieved content
143135 output_text = response .output_text if hasattr (response , "output_text" ) else ""
144- output_results = self ._client ._run_stage_guardrails (
145- "output" , output_text , suppress_tripwire = suppress_tripwire
146- )
136+ output_results = self ._client ._run_stage_guardrails ("output" , output_text , suppress_tripwire = suppress_tripwire )
147137
148138 # Return wrapped response with guardrail results
149139 return self ._client ._create_guardrails_response (
150- response , [], [], output_results # preflight # input
140+ response ,
141+ [],
142+ [],
143+ output_results , # preflight # input
151144 )
152145
153146
154147class AsyncResponses :
155148 """Responses API with guardrails (async)."""
156149
157150 def __init__ (self , client ):
151+ """Initialize AsyncResponses resource.
152+
153+ Args:
154+ client: GuardrailsBaseClient instance with configured guardrails.
155+ """
158156 self ._client = client
159157
160158 async def create (
@@ -164,7 +162,7 @@ async def create(
164162 stream : bool = False ,
165163 tools : list [dict ] | None = None ,
166164 suppress_tripwire : bool = False ,
167- ** kwargs
165+ ** kwargs ,
168166 ) -> Any | AsyncIterator [Any ]:
169167 """Create response with guardrails."""
170168 # Determine latest user message text when a list of messages is provided
@@ -182,9 +180,7 @@ async def create(
182180 )
183181
184182 # Apply pre-flight modifications (PII masking, etc.)
185- modified_input = self ._client ._apply_preflight_modifications (
186- input , preflight_results
187- )
183+ modified_input = self ._client ._apply_preflight_modifications (input , preflight_results )
188184
189185 # Run input guardrails and LLM call in parallel
190186 input_check = self ._client ._run_stage_guardrails (
@@ -220,13 +216,7 @@ async def create(
220216 )
221217
222218 async def parse (
223- self ,
224- input : list [dict [str , str ]],
225- model : str ,
226- text_format : type [BaseModel ],
227- stream : bool = False ,
228- suppress_tripwire : bool = False ,
229- ** kwargs
219+ self , input : list [dict [str , str ]], model : str , text_format : type [BaseModel ], stream : bool = False , suppress_tripwire : bool = False , ** kwargs
230220 ) -> Any | AsyncIterator [Any ]:
231221 """Parse response with structured output and guardrails."""
232222 latest_message , _ = self ._client ._extract_latest_user_message (input )
@@ -240,9 +230,7 @@ async def parse(
240230 )
241231
242232 # Apply pre-flight modifications (PII masking, etc.)
243- modified_input = self ._client ._apply_preflight_modifications (
244- input , preflight_results
245- )
233+ modified_input = self ._client ._apply_preflight_modifications (input , preflight_results )
246234
247235 # Run input guardrails and LLM call in parallel
248236 input_check = self ._client ._run_stage_guardrails (
@@ -277,22 +265,19 @@ async def parse(
277265 suppress_tripwire = suppress_tripwire ,
278266 )
279267
280- async def retrieve (
281- self , response_id : str , suppress_tripwire : bool = False , ** kwargs
282- ):
268+ async def retrieve (self , response_id : str , suppress_tripwire : bool = False , ** kwargs ):
283269 """Retrieve response with output guardrail validation."""
284270 # Get the response using the original OpenAI client
285- response = await self ._client ._resource_client .responses .retrieve (
286- response_id , ** kwargs
287- )
271+ response = await self ._client ._resource_client .responses .retrieve (response_id , ** kwargs )
288272
289273 # Run output guardrails on the retrieved content
290274 output_text = response .output_text if hasattr (response , "output_text" ) else ""
291- output_results = await self ._client ._run_stage_guardrails (
292- "output" , output_text , suppress_tripwire = suppress_tripwire
293- )
275+ output_results = await self ._client ._run_stage_guardrails ("output" , output_text , suppress_tripwire = suppress_tripwire )
294276
295277 # Return wrapped response with guardrail results
296278 return self ._client ._create_guardrails_response (
297- response , [], [], output_results # preflight # input
279+ response ,
280+ [],
281+ [],
282+ output_results , # preflight # input
298283 )
0 commit comments