Shield Decorators

Reference for Python Shield decorators, including prompt, tool, tool response, model response, and generic wrappers.

Use Shield decorators when you want guardrails to run automatically around your application code.

from highflame import Highflame
from highflame.shield import Shield

client = Highflame(api_key="hf_sk_...")
shield = Shield(client)

@shield.prompt

Guards the prompt content before the function runs. If denied, the function is never called.

# Bare decorator — defaults apply
@shield.prompt
def chat(message: str) -> str:
    return llm.complete(message)


# With options
@shield.prompt(mode="monitor", content_arg="user_input", session_id="sess_abc")
def chat(context: str, user_input: str) -> str:
    return llm.complete(user_input)
Option
Type
Default
Description

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

content_arg

str

first str param

Name of the parameter to guard

session_id

str | None

None

Session ID for tracking

@shield.tool

Guards tool arguments before the tool executes. If denied, the function is never called. All bound arguments are forwarded as tool-call context.

Option
Type
Default
Description

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

tool_name

str | None

function name

Tool name sent to the service

session_id

str | None

None

Session ID

@shield.toolresponse

Guards the tool's return value after the function runs. The function always executes; its return value is blocked if denied.

Option
Type
Default
Description

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

tool_name

str | None

function name

Tool name sent to the service

session_id

str | None

None

Session ID

@shield.modelresponse

Guards the LLM's output before returning it to the caller. The function always executes; its return value is blocked if denied.

Option
Type
Default
Description

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

session_id

str | None

None

Session ID

@shield() Generic Decorator

Use the generic decorator when you need a content type or action not covered by the named decorators.

Option
Type
Default
Description

content_type

str

required

Content type such as "file" or "prompt"

action

str

required

Action such as "write_file"

content_arg

str | None

first str param

Parameter to guard

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

session_id

str | None

None

Session ID

Last updated