Skip to content

Security Policy / X-Policy

Configure security policies using SQRT policy language.

SecurityPolicyHeader pydantic-model

Configuration header for Sequrity security policies (X-Policy).

Defines the rules and constraints that govern LLM behavior.

Example
policy = SecurityPolicyHeader.dual_llm(codes="allow tool x;")
policy = SecurityPolicyHeader.single_llm()
Show JSON schema:
{
  "$defs": {
    "ControlFlowMetaPolicy": {
      "description": "Control flow meta policy for branching tools.",
      "properties": {
        "mode": {
          "default": "deny",
          "description": "'allow' for whitelist, 'deny' for blacklist.",
          "enum": [
            "allow",
            "deny"
          ],
          "title": "Mode",
          "type": "string"
        },
        "producers": {
          "description": "Set of prohibited producers for control flow relaxer in custom mode.",
          "items": {
            "type": "string"
          },
          "title": "Producers",
          "type": "array",
          "uniqueItems": true
        },
        "tags": {
          "description": "Set of prohibited tags for control flow relaxer in custom mode.",
          "items": {
            "type": "string"
          },
          "title": "Tags",
          "type": "array",
          "uniqueItems": true
        },
        "consumers": {
          "description": "Set of prohibited consumers for control flow relaxer in custom mode.",
          "items": {
            "type": "string"
          },
          "title": "Consumers",
          "type": "array",
          "uniqueItems": true
        }
      },
      "title": "ControlFlowMetaPolicy",
      "type": "object"
    },
    "InternalPolicyPresets": {
      "additionalProperties": false,
      "description": "Internal policy presets for advanced policy configuration.",
      "properties": {
        "default_allow": {
          "default": true,
          "description": "Whether to allow tool calls by default.",
          "title": "Default Allow",
          "type": "boolean"
        },
        "default_allow_enforcement_level": {
          "default": "soft",
          "description": "Enforcement level for default allow policy.",
          "enum": [
            "hard",
            "soft"
          ],
          "title": "Default Allow Enforcement Level",
          "type": "string"
        },
        "enable_non_executable_memory": {
          "default": true,
          "description": "Whether to enable non-executable memory internal policy (attach non-executable tag to all tool results by default).",
          "title": "Enable Non Executable Memory",
          "type": "boolean"
        },
        "branching_meta_policy": {
          "$ref": "#/$defs/ControlFlowMetaPolicy"
        },
        "enable_llm_blocked_tag": {
          "default": true,
          "description": "Whether to enable LLM blocked tag internal policy (denies tool calls to parse_with_ai if any argument has LLM_BLOCKED_TAG).",
          "title": "Enable Llm Blocked Tag",
          "type": "boolean"
        },
        "llm_blocked_tag_enforcement_level": {
          "default": "hard",
          "description": "Enforcement level for LLM blocked tag internal policy.",
          "enum": [
            "hard",
            "soft"
          ],
          "title": "Llm Blocked Tag Enforcement Level",
          "type": "string"
        }
      },
      "title": "InternalPolicyPresets",
      "type": "object"
    },
    "PolicyCode": {
      "additionalProperties": false,
      "description": "Security policy code container.\n\nAttributes:\n    code: The security policy code as a single string.\n    language: The language of the policy code (\"sqrt\" or \"cedar\").",
      "properties": {
        "code": {
          "default": "",
          "description": "The security policy code as a single string.",
          "title": "Code",
          "type": "string"
        },
        "language": {
          "default": "sqrt",
          "description": "The language of the policy code.",
          "enum": [
            "sqrt",
            "cedar"
          ],
          "title": "Language",
          "type": "string"
        }
      },
      "title": "PolicyCode",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "Configuration header for Sequrity security policies (``X-Policy``).\n\nDefines the rules and constraints that govern LLM behavior.\n\nExample:\n    ```python\n    policy = SecurityPolicyHeader.dual_llm(codes=\"allow tool x;\")\n    policy = SecurityPolicyHeader.single_llm()\n    ```",
  "properties": {
    "mode": {
      "anyOf": [
        {
          "enum": [
            "standard",
            "strict",
            "custom"
          ],
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "The security mode: standard, strict, or custom.",
      "title": "Mode"
    },
    "codes": {
      "anyOf": [
        {
          "$ref": "#/$defs/PolicyCode"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "User security policy code."
    },
    "auto_gen": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Whether to auto-generate policies based on tool metadata and natural language descriptions.",
      "title": "Auto Gen"
    },
    "fail_fast": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Whether to fail fast on first hard denial during policy checks.",
      "title": "Fail Fast"
    },
    "presets": {
      "anyOf": [
        {
          "$ref": "#/$defs/InternalPolicyPresets"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "description": "Internal policy presets configuration."
    }
  },
  "title": "SecurityPolicyHeader",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

single_llm classmethod

single_llm(
    mode: Literal["standard", "strict", "custom"] = "standard",
    codes: str = "",
    language: Literal["sqrt", "cedar"] = "sqrt",
    fail_fast: bool | None = None,
    default_allow: bool = True,
    enable_llm_blocked_tag: bool = True,
    llm_blocked_tag_enforcement_level: Literal["hard", "soft"] = "hard",
) -> SecurityPolicyHeader

Create a Single LLM security policy configuration.

Source code in src/sequrity/control/types/headers.py
@classmethod
def single_llm(
    cls,
    mode: Literal["standard", "strict", "custom"] = "standard",
    codes: str = "",
    language: Literal["sqrt", "cedar"] = "sqrt",
    fail_fast: bool | None = None,
    default_allow: bool = True,
    enable_llm_blocked_tag: bool = True,
    llm_blocked_tag_enforcement_level: Literal["hard", "soft"] = "hard",
) -> SecurityPolicyHeader:
    """Create a Single LLM security policy configuration."""
    return cls.model_validate(
        {
            "mode": mode,
            "codes": {"code": codes, "language": language},
            "auto_gen": False,
            "fail_fast": fail_fast,
            "presets": {
                "default_allow": default_allow,
                "enable_non_executable_memory": False,
                "enable_llm_blocked_tag": enable_llm_blocked_tag,
                "llm_blocked_tag_enforcement_level": llm_blocked_tag_enforcement_level,
            },
        }
    )

dual_llm classmethod

dual_llm(
    mode: Literal["standard", "strict", "custom"] = "standard",
    codes: str = "",
    language: Literal["sqrt", "cedar"] = "sqrt",
    auto_gen: bool = False,
    fail_fast: bool | None = None,
    default_allow: bool = True,
    default_allow_enforcement_level: Literal["hard", "soft"] = "soft",
    enable_non_executable_memory: bool = True,
    enable_llm_blocked_tag: bool = True,
    llm_blocked_tag_enforcement_level: Literal["hard", "soft"] = "hard",
    branching_meta_policy_mode: Literal["allow", "deny"] = "deny",
    branching_meta_policy_producers: set[str] | None = None,
    branching_meta_policy_tags: set[str] | None = None,
    branching_meta_policy_consumers: set[str] | None = None,
) -> SecurityPolicyHeader

Create a Dual LLM security policy configuration.

Source code in src/sequrity/control/types/headers.py
@classmethod
def dual_llm(
    cls,
    mode: Literal["standard", "strict", "custom"] = "standard",
    codes: str = "",
    language: Literal["sqrt", "cedar"] = "sqrt",
    auto_gen: bool = False,
    fail_fast: bool | None = None,
    default_allow: bool = True,
    default_allow_enforcement_level: Literal["hard", "soft"] = "soft",
    enable_non_executable_memory: bool = True,
    enable_llm_blocked_tag: bool = True,
    llm_blocked_tag_enforcement_level: Literal["hard", "soft"] = "hard",
    branching_meta_policy_mode: Literal["allow", "deny"] = "deny",
    branching_meta_policy_producers: set[str] | None = None,
    branching_meta_policy_tags: set[str] | None = None,
    branching_meta_policy_consumers: set[str] | None = None,
) -> SecurityPolicyHeader:
    """Create a Dual LLM security policy configuration."""
    return cls.model_validate(
        {
            "mode": mode,
            "codes": {"code": codes, "language": language},
            "auto_gen": auto_gen,
            "fail_fast": fail_fast,
            "presets": {
                "default_allow": default_allow,
                "default_allow_enforcement_level": default_allow_enforcement_level,
                "enable_non_executable_memory": enable_non_executable_memory,
                "enable_llm_blocked_tag": enable_llm_blocked_tag,
                "llm_blocked_tag_enforcement_level": llm_blocked_tag_enforcement_level,
                "branching_meta_policy": {
                    "mode": branching_meta_policy_mode,
                    "producers": branching_meta_policy_producers or set(),
                    "tags": branching_meta_policy_tags or set(),
                    "consumers": branching_meta_policy_consumers or set(),
                },
            },
        }
    )

dump_for_headers

dump_for_headers(
    mode: Literal["json_str"] = ..., *, overrides: dict[str, Any] | None = ...
) -> str
dump_for_headers(
    mode: Literal["json"], *, overrides: dict[str, Any] | None = ...
) -> dict
dump_for_headers(
    mode: Literal["json", "json_str"] = "json_str",
    *,
    overrides: dict[str, Any] | None = None,
) -> dict | str

Serialize for use as the X-Policy HTTP header value.

Parameters:

  • mode

    (Literal['json', 'json_str'], default: 'json_str' ) –

    Output format — "json" for a dict, "json_str" for a JSON string.

  • overrides

    (dict[str, Any] | None, default: None ) –

    Optional dict to deep-merge into the serialized output.

Source code in src/sequrity/control/types/headers.py
def dump_for_headers(
    self, mode: Literal["json", "json_str"] = "json_str", *, overrides: dict[str, Any] | None = None
) -> dict | str:
    """Serialize for use as the ``X-Policy`` HTTP header value.

    Args:
        mode: Output format — ``"json"`` for a dict, ``"json_str"`` for a JSON string.
        overrides: Optional dict to deep-merge into the serialized output.
    """
    data = self.model_dump(mode="json", exclude_none=True)
    if overrides:
        _deep_merge(data, overrides)
    if mode == "json":
        return data
    elif mode == "json_str":
        return json.dumps(data)
    else:
        raise ValueError(f"Unsupported mode for dump_for_headers: {mode}")

PolicyCode pydantic-model

Security policy code container.

Attributes:

  • code (str) –

    The security policy code as a single string.

  • language (Literal['sqrt', 'cedar']) –

    The language of the policy code ("sqrt" or "cedar").

Show JSON schema:
{
  "additionalProperties": false,
  "description": "Security policy code container.\n\nAttributes:\n    code: The security policy code as a single string.\n    language: The language of the policy code (\"sqrt\" or \"cedar\").",
  "properties": {
    "code": {
      "default": "",
      "description": "The security policy code as a single string.",
      "title": "Code",
      "type": "string"
    },
    "language": {
      "default": "sqrt",
      "description": "The language of the policy code.",
      "enum": [
        "sqrt",
        "cedar"
      ],
      "title": "Language",
      "type": "string"
    }
  },
  "title": "PolicyCode",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

code pydantic-field

code: str = ''

The security policy code as a single string.

language pydantic-field

language: Literal['sqrt', 'cedar'] = 'sqrt'

The language of the policy code.

InternalPolicyPresets pydantic-model

Internal policy presets for advanced policy configuration.

Show JSON schema:
{
  "$defs": {
    "ControlFlowMetaPolicy": {
      "description": "Control flow meta policy for branching tools.",
      "properties": {
        "mode": {
          "default": "deny",
          "description": "'allow' for whitelist, 'deny' for blacklist.",
          "enum": [
            "allow",
            "deny"
          ],
          "title": "Mode",
          "type": "string"
        },
        "producers": {
          "description": "Set of prohibited producers for control flow relaxer in custom mode.",
          "items": {
            "type": "string"
          },
          "title": "Producers",
          "type": "array",
          "uniqueItems": true
        },
        "tags": {
          "description": "Set of prohibited tags for control flow relaxer in custom mode.",
          "items": {
            "type": "string"
          },
          "title": "Tags",
          "type": "array",
          "uniqueItems": true
        },
        "consumers": {
          "description": "Set of prohibited consumers for control flow relaxer in custom mode.",
          "items": {
            "type": "string"
          },
          "title": "Consumers",
          "type": "array",
          "uniqueItems": true
        }
      },
      "title": "ControlFlowMetaPolicy",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "Internal policy presets for advanced policy configuration.",
  "properties": {
    "default_allow": {
      "default": true,
      "description": "Whether to allow tool calls by default.",
      "title": "Default Allow",
      "type": "boolean"
    },
    "default_allow_enforcement_level": {
      "default": "soft",
      "description": "Enforcement level for default allow policy.",
      "enum": [
        "hard",
        "soft"
      ],
      "title": "Default Allow Enforcement Level",
      "type": "string"
    },
    "enable_non_executable_memory": {
      "default": true,
      "description": "Whether to enable non-executable memory internal policy (attach non-executable tag to all tool results by default).",
      "title": "Enable Non Executable Memory",
      "type": "boolean"
    },
    "branching_meta_policy": {
      "$ref": "#/$defs/ControlFlowMetaPolicy"
    },
    "enable_llm_blocked_tag": {
      "default": true,
      "description": "Whether to enable LLM blocked tag internal policy (denies tool calls to parse_with_ai if any argument has LLM_BLOCKED_TAG).",
      "title": "Enable Llm Blocked Tag",
      "type": "boolean"
    },
    "llm_blocked_tag_enforcement_level": {
      "default": "hard",
      "description": "Enforcement level for LLM blocked tag internal policy.",
      "enum": [
        "hard",
        "soft"
      ],
      "title": "Llm Blocked Tag Enforcement Level",
      "type": "string"
    }
  },
  "title": "InternalPolicyPresets",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

default_allow pydantic-field

default_allow: bool = True

Whether to allow tool calls by default.

default_allow_enforcement_level pydantic-field

default_allow_enforcement_level: Literal['hard', 'soft'] = 'soft'

Enforcement level for default allow policy.

enable_non_executable_memory pydantic-field

enable_non_executable_memory: bool = True

Whether to enable non-executable memory internal policy (attach non-executable tag to all tool results by default).

branching_meta_policy pydantic-field

branching_meta_policy: ControlFlowMetaPolicy

Control flow meta policy for branching tools.

enable_llm_blocked_tag pydantic-field

enable_llm_blocked_tag: bool = True

Whether to enable LLM blocked tag internal policy (denies tool calls to parse_with_ai if any argument has LLM_BLOCKED_TAG).

llm_blocked_tag_enforcement_level pydantic-field

llm_blocked_tag_enforcement_level: Literal['hard', 'soft'] = 'hard'

Enforcement level for LLM blocked tag internal policy.

ControlFlowMetaPolicy pydantic-model

Control flow meta policy for branching tools.

Show JSON schema:
{
  "description": "Control flow meta policy for branching tools.",
  "properties": {
    "mode": {
      "default": "deny",
      "description": "'allow' for whitelist, 'deny' for blacklist.",
      "enum": [
        "allow",
        "deny"
      ],
      "title": "Mode",
      "type": "string"
    },
    "producers": {
      "description": "Set of prohibited producers for control flow relaxer in custom mode.",
      "items": {
        "type": "string"
      },
      "title": "Producers",
      "type": "array",
      "uniqueItems": true
    },
    "tags": {
      "description": "Set of prohibited tags for control flow relaxer in custom mode.",
      "items": {
        "type": "string"
      },
      "title": "Tags",
      "type": "array",
      "uniqueItems": true
    },
    "consumers": {
      "description": "Set of prohibited consumers for control flow relaxer in custom mode.",
      "items": {
        "type": "string"
      },
      "title": "Consumers",
      "type": "array",
      "uniqueItems": true
    }
  },
  "title": "ControlFlowMetaPolicy",
  "type": "object"
}

Fields:

mode pydantic-field

mode: Literal['allow', 'deny'] = 'deny'

'allow' for whitelist, 'deny' for blacklist.

producers pydantic-field

producers: set[str]

Set of prohibited producers for control flow relaxer in custom mode.

tags pydantic-field

tags: set[str]

Set of prohibited tags for control flow relaxer in custom mode.

consumers pydantic-field

consumers: set[str]

Set of prohibited consumers for control flow relaxer in custom mode.