Skip to main content

5.1 Argus Client: Your Central Guard

The ArgusClient is the primary interface for all interactions with the Argus API. It is designed to be a long-lived object within your application. Best Practice: In a web server or long-running application, you should create a single, shared instance of the ArgusClient when your application starts and reuse it for all subsequent requests. Creating a new client for every request is inefficient and will introduce significant latency due to repeated authentication and connection setup. The SDK intelligently distinguishes between user tiers based on the provided API key, automatically enabling or disabling platform-specific features. You do not need to specify your user level; the client handles it for you.

5.2 Anatomy of a Scan: Inputs and Outputs

Every scan consists of well-defined inputs (your security rules) and outputs (the scan result).

Inputs: Defining Your Security Rules

You control the behavior of a scan by defining a Policy. A policy is built using several key components:

The Action Enum: What to Do

The Action enum can be used to define what action to take for a policy violation

The InteractionType Enum: What You’re Scanning

This enum provides context to the scanner about the nature of the text being analyzed.

The Policy Object: Your Complete Security Configuration

The Policy object is the heart of your security rules. It is a Python dictionary where keys are members of the PolicyName enum and values are configuration dictionaries. Each configuration dictionary must contain an "action" key with a value from the Action enum. Some policies require additional configuration keys, as detailed below. Comprehensive Policy Object Example:
PolicyName Configuration Requirements:

Outputs: Understanding the Scan Result

Every scan method returns a consistent ApiResult object. To ensure type safety and prevent bugs from typos, you should always use the Verdict enum when interpreting the result.

The Verdict Enum: The Final Outcome

The ApiResult Object: Structure and Attributes

All scan methods return an ApiResult object which provides the complete, structured outcome of the scan. This serves as the single source of truth for the scan’s results. Top-Level Attributes

The AppliedPolicyInfo Object Structure

This object confirms which policies were part of the scan evaluation.

The ViolatedPolicyInfo Object Structure

This object provides detailed context about a specific violation.

details Object Schema by Policy

The structure of the details object is unique to each policy, providing the most relevant information for that specific risk type.

5.3 Client State vs. Call-Time Overrides: Two Ways to Configure

The SDK provides two powerful patterns for applying policies and configurations: setting a default state on the client and overriding that state for individual calls.

Method 1: Configuring the Client’s Default State

You can configure a default security posture when you initialize the ArgusClient. This state will be automatically applied to every scan call that does not have an explicit override. This is the most common pattern for applications with a consistent security requirement. Default state can be set for:
  • policy
  • asset_id (Platform Only)
  • session_id (Platform Only)
  • save (Platform Only)
You can also modify this state after creation using the client’s state management methods (set_policies(), set_asset_id(), etc.). Example: Setting a Default State

Method 2: Using Call-Time Overrides for Dynamic Control

For maximum flexibility, every parameter you can set at creation time can also be overridden for a single API call by passing it directly to the check_prompt() or check_response() methods. This override is temporary and does not affect the client’s default state. It is perfect for situations where you need to apply a different policy or log to a different asset dynamically. Example: Temporarily Overriding the Default State

5.4 Agentic Threat Observability with Guardrail Decorators (Platform Tier)

For users with a Platform Tier key (rsk_...), the SDK offers a feature set that goes far beyond simple scanning: full-stack observability for agentic workflows. This is primarily achieved through a powerful set of Guardrail Decorators. Instead of manually calling check_content() before and after every function call, you can use these decorators to declaratively trace and protect your entire application. The SDK automatically handles creating execution timelines, applying policies, and logging all the data to the Argus Platform for visualization.

The Core Concept: Traces and Spans

Think of how a debugger’s call stack helps you understand a traditional application’s flow. Argus decorators provide a similar concept for your AI system:
  • Trace: A trace represents the entire end-to-end execution of a single workflow. For example, a user’s entire request from “start research” to “get final answer” would be one trace.
  • Span: A span represents a single, instrumented unit of work within that trace. Each function you wrap with a guardrail decorator creates a new span.
This creates a hierarchical view in the Argus dashboard, allowing you to see exactly how your agent made its decisions, which tools it used, and where a security violation occurred.

The Primary Decorators

There are three main decorators, each designed for a specific role in an agentic workflow. Using them correctly provides the richest possible context in your observability traces.

1. @client.guard_entrypoint()

This decorator should be used on the single function that kicks off your entire workflow. It wraps the top-level span of the trace.
  • Purpose: Marks the beginning and end of the entire operation.
  • Typical Use: Placed on a function like main(), run_agent(), or a web server’s primary request handler.

2. @client.guard_agent()

This decorator is for wrapping the core logic or decision-making components of your system.
  • Purpose: Represents a logical “agent” or a major step in the workflow. It’s the “brains” of the operation.
  • Key Behavior: By default, guard_agent does not scan the output of the function (check_output=False). This is because agents often return complex objects, control signals, or iterators—not just raw text that needs scanning. Its primary role is to create a logical grouping span in the trace.

3. @client.guard_tool()

This is the most common decorator and the workhorse for security enforcement. It should be used to wrap individual tools that your agent can call.
  • Purpose: Wraps functions that perform a specific, isolated task, especially those that interact with the outside world (e.g., calling an API, querying a database, running code).
  • Key Behavior: This is where you will most frequently apply security policies. It defaults to scanning the function’s output (check_output=True), as tools often return external data that needs to be validated before being passed back to the agent.

A Cohesive Example: A Simple Research Agent

Let’s see how these decorators work together to trace and protect a simple agent that uses a search tool and a summarization tool.
When you run the code above, the Argus Platform will receive a trace that looks like this, clearly showing the agent’s flow and the security finding from the WebSearchTool:
  • MainAppEntry (Trace Root)
    • ResearchAgentLogic (Span)
      • WebSearchTool (Sub-Span) -> VIOLATION FLAGGED: Banned Topic ‘finance’ detected.
      • SummarizationTool (Sub-Span)

Key Decorator Parameters

You can customize the behavior of any guardrail decorator with these optional parameters:

Optional: callback and GuardrailEvent

Decorators accept an optional callback with the signature (GuardrailEvent) -> None. The SDK passes a single GuardrailEvent per scan; see the SDK reference for all fields (node_name, payload, scan_result including verdict, request_policy, node_metadata, session_id). When it runs: Once after each listed check_input_args value is scanned (if any). The wrapped function then runs. If check_output is True and the return value is not None, the output is scanned and the callback runs again for that result. Semantic aliases such as @client.guard_database() forward callback the same way as @client.guard_tool(). What it is not: Put your main application logic in the decorated function. The callback is for side effects (observability, custom handling). It does not replace the wrapped function or change its return value. If the callback raises an exception, execution stops before the body runs (when raised during an input scan) or after the body returns (when raised during an output scan).

Convenience Aliases

For common tool types, the SDK provides semantic aliases for @client.guard_tool to make your traces more readable. These are functionally identical to @client.guard_tool but assign a different default subtype icon in the UI.
  • @client.guard_database()
  • @client.guard_knowledge_base()
  • @client.guard_model_generation()

5.5 Observability and Platform Integration (Platform Tier)

For users with a Runtime Security Key, the SDK unlocks a powerful set of features centered around the Argus Platform dashboard, transforming the SDK from a simple scanner into a comprehensive security and observability tool.

Leveraging Platform-Managed Policies

This is the primary and most powerful workflow for Platform users. Instead of defining complex Policy objects in your code, you can build, test, and manage them entirely within the Argus UI. Your security, legal, and product teams can collaborate on policies without requiring code changes. To use a platform-managed policy, simply associate your client with an Asset ID and make scan calls without a local policy object.

Organizing Your Data with Assets (asset_id)

An Asset is a logical container in the Argus Platform that represents a specific application, environment, or use case you are protecting (e.g., “Production Support Chatbot”, “Staging Marketing Assistant”, “Developer Sandbox”).
  • Why use Assets? They allow you to apply different policies to different applications and view their analytics separately in the dashboard.
  • How to use: You can set a default asset_id when creating the client or override it on a per-call basis, which is ideal for centralized AI gateways managing multiple applications.

Tracking Conversations with Sessions (session_id)

A Session is a unique identifier that you create and manage to group a series of related interactions. For a chatbot, a session would typically represent a single user’s complete conversation from start to finish.
  • Why use Sessions? They are critical for observability. In the Argus dashboard, all prompts and responses with the same session_id are linked, allowing you to review the full context of a conversation to understand why a policy was triggered.
  • How to use: You can manage sessions in two ways, depending on your application’s architecture. **Method 1: Passing **session_idper Call (Stateless) This is the most common and robust pattern, especially for web servers or stateless applications where a single ArgusClient instance may handle requests from many different users simultaneously. You pass the session_id as a parameter to each scan call.
    **Method 2: Setting **session_idon the Client (Stateful) This pattern is useful in scenarios where a client instance or process is dedicated to a single, stateful conversation (e.g., a worker process, a desktop application, or a chatbot object). You set the session_id once on the client and then clear it when the conversation is over.

Persisting Data for Analytics (save=True)

The save parameter controls whether the full details of a scan (input, output, verdict, etc.) are persisted in the Argus Platform.
  • save=True: This is the standard for production environments. It populates your Argus dashboard with the data needed for analytics, log investigation, and model performance monitoring. An asset_id is required to save data.
  • save=False: This is useful for development, testing, or scenarios where you do not want to clutter your production analytics. You can perform a scan and get a verdict without the record being stored.
This parameter can be set as a client default and also be overridden on a per-call basis. For example, an AI gateway could set save=True by default but override to save=False for requests coming from a developer’s test script. |