Demonstrates how to add CodeRifts enforcement to OpenAI function calling, blocking unsafe API calls before execution.
pip install requests
python main.pyThe handle_tool_call function wraps every tool execution with a CodeRifts preflight check:
def handle_tool_call(tool_call):
args = json.loads(tool_call["arguments"])
decision = coderifts_preflight(args["spec_url"])
if decision["decision"] == "BLOCK":
return json.dumps({"error": "blocked_by_coderifts"})
# Safe to proceed
return execute_api_call(args)The model receives the block result as a tool response and can explain to the user why the call was blocked.
[OPENAI] Model wants to call API at https://petstore3.swagger.io/api/v3/openapi.json
[CODERIFTS] decision=ALLOW risk=12
[OPENAI] Executing /orders/123 on https://petstore3.swagger.io/api/v3/openapi.json
[OPENAI] Tool call succeeded: {"status": "success", "data": {"order_id": "12345"}}