Shield Wrappers

Reference for TypeScript Shield wrappers, including prompt, tool, tool response, model response, and generic wrap patterns.

Use Shield wrappers when you want guardrails to run automatically around your functions.

import { Highflame, Shield } from "@highflame/sdk";

const client = new Highflame({ apiKey: "hf_sk_..." });
const shield = new Shield(client);

shield.prompt(fn, options?)

Guards a prompt input before the function runs. If denied, fn is never called.

const chat = shield.prompt(async (message: string) => llm.complete(message));

const guardedChat = shield.prompt(
  async (context: string, userMessage: string) => llm.complete(context, userMessage),
  { contentArg: 1 },
);

const monitoredChat = shield.prompt(async (msg: string) => llm.complete(msg), {
  mode: "monitor",
  sessionId: "sess_user_abc",
});
Option
Type
Default
Description

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

contentArg

number

0

Zero-based index of the argument to guard

sessionId

string

Session ID for cross-turn tracking

shield.tool(fn, options?)

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

Option
Type
Default
Description

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

toolName

string

fn.name

Override the tool name

sessionId

string

Session ID

shield.toolResponse(fn, options?)

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

Option
Type
Default
Description

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

toolName

string

fn.name

Tool name included in the request

sessionId

string

Session ID

shield.modelResponse(fn, options?)

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

Option
Type
Default
Description

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

sessionId

string

Session ID

shield.wrap(options)

Generic wrapper for content types and actions not covered by the named shorthands.

Option
Type
Default
Description

contentType

"prompt" | "response" | "tool_call" | "file"

required

Content type

action

"process_prompt" | "call_tool" | "read_file" | "write_file" | "connect_server"

required

Cedar action

contentArg

number

0

Zero-based argument index to use as content

mode

"enforce" | "monitor" | "alert"

"enforce"

Enforcement mode

sessionId

string

Session ID

Last updated