liveBook · Manning

Validation

As explained in Designing AI Systems

Input validation is the process of checking incoming requests or data against defined validity, safety, and policy requirements before processing.

Validation checks requests and data against defined safety and policy requirements before processing. In an AI assistant, it can stop an out-of-scope request before it reaches the model and check model-generated tool arguments before execution. section 6.7.1 section 10.7

Define safety policies once and enforce them through a guardrails service rather than embedding detection logic in every workflow. Policies can block a request or redirect the user with an appropriate response; application-specific rules determine what is allowed. section 2.1.4 section 6.7.1

Validate different inputs at the boundary where they matter:

  • Check user messages for attacks and permitted topics before invoking the model. A blocked topic can receive an immediate response without consuming model tokens. section 6.7.1 section 10.7
  • Check tool arguments for required fields and types, then enforce value constraints and valid references. A booking date in the past should not reach the scheduling API. section 6.7.1
  • Check action context as well as arguments. A patient ID can be required to match the authenticated user, and session-level limits can independently constrain repeated tool calls. section 6.7.1 section 10.7
Listing 6.22 Schema and constraint validation for tool arguments
platform.guardrails.add_policy(
    name="book-appointment-arguments",
    type="tool_validation",
    rules=[
        {
            "tool": "healthcare.scheduling.book_appointment",
            "constraints": [
                {
                    "field": "appointment_date",
                    "checks": [
                        {"type": "future_date", "min_days_ahead": 1},
                        {"type": "max_days_ahead", "days": 90},
                        {"type": "business_hours", "timezone": "America/New_York"}
                    ]
                },
                {
                    "field": "patient_id",
                    "checks": [
                        {"type": "matches_session_user"},                #A
                        {"type": "exists_in_system", "lookup": "patient_registry"}
                    ]
                },
                {
                    "field": "appointment_type",
                    "checks": [
                        {"type": "in_list", "source": "allowed_appointment_types"},
                        {"type": "custom",
                         "validator": "check_referral_requirement"}      #B
                    ]
                }
            ]
        }
    ]
)

This policy configures date, business-hours, identity, and registry checks for booking arguments. section 6.7.1

In an agent loop, validate each proposed tool call before execution. When a check fails, return the denial reason as a tool message and skip execution; passing calls proceed to the tool service. section 10.7

Listing 10.13 Tool argument validation within the agent loop
for tool_call in response.tool_calls:
    name = tool_names[tool_call["function"]["name"]]
    args = json.loads(tool_call["function"]["arguments"])
    args_check = platform.guardrails.check_policy(    #A
        policy_name="claw-action-limits",    #A
        action=name,    #A
        context={    #A
            "user_id": user_id,    #A
            "session_id": session_id    #A
        },    #A
        arguments=args    #A
    )    #A
 
    if not args_check.allowed:    #B
        messages.append({    #B
            "role": "tool",    #B
            "content": f"Action blocked: {args_check.denial_reason}",    #B
            "tool_call_id": tool_call["id"]    #B
        })    #B
        continue    #C
 
    result = platform.tools.execute(
        tool_name=name, arguments=args,
        session_id=session_id
    )
 
    messages.append({
        "role": "tool",
        "content": str(result.result),
        "tool_call_id": tool_call["id"]
    })

The agent loop supplies the action, arguments, user, and session to a policy check before executing a tool. section 10.7

Input and argument validation are part of defense in depth, not substitutes for output filtering. Validate or filter responses before delivery to catch policy violations or unsupported claims that earlier checks did not prevent. section 2.1.4 section 1.5

How Designing AI Systems covers it

How deep it goes
Details declarative policies, schema and constraint checks, denial handling, and their placement in an agent loop.
Examples
Uses healthcare intake, appointment booking, calendar events, and session-limited ticket creation to illustrate policy checks.
What you can do after
Apply it via the platform guardrails API to configure policies and check inputs and tool arguments before execution.
How it connects
Connects guardrails, prompt injection detection, topic classification, schema validation, tool execution, and output filtering.

Also explained in

Compare how 44 books explain validation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Designing AI Systems. The section links point to the parts of the book it draws on.