Skip to content

Policy Generation

The Policy Generation API generates SQRT security policies from natural language descriptions.

PolicyResource

PolicyResource(transport: ControlSyncTransport)

Policy generation — client.control.policy.

Methods:

  • generate

    Generate a SQRT security policy from a natural language description.

generate

generate(
    request: PolicyGenRequest | dict,
    *,
    llm_api_key: str | None | _NotGiven = NOT_GIVEN,
    custom_headers: dict[str, str] | None = None,
) -> PolicyGenResponse

Generate a SQRT security policy from a natural language description.

Parameters:

  • request

    (PolicyGenRequest | dict) –

    Policy generation request, either as a typed Pydantic model or a raw dict. The request must include a type discriminator field to select the tool format variant.

  • llm_api_key

    (str | None | _NotGiven, default: NOT_GIVEN ) –

    Optional LLM provider API key override.

  • custom_headers

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

    Optional extra HTTP headers to include in the request.

Returns:

  • PolicyGenResponse

    Parsed PolicyGenResponse with generated policies and usage info.


Request Types

PolicyGenRequestBase pydantic-model

Base fields shared by all policy generation request variants.

Show JSON schema:
{
  "description": "Base fields shared by all policy generation request variants.",
  "properties": {
    "model": {
      "description": "The model to use for policy generation.",
      "title": "Model",
      "type": "string"
    },
    "description": {
      "description": "A description of the policy to generate in natural language.",
      "title": "Description",
      "type": "string"
    },
    "policy_lang": {
      "const": "sqrt",
      "default": "sqrt",
      "description": "The policy language to generate the policy in.",
      "title": "Policy Lang",
      "type": "string"
    },
    "n_retries": {
      "default": 3,
      "description": "The number of times to retry policy generation if it fails or the generated policy is invalid.",
      "minimum": 0,
      "title": "N Retries",
      "type": "integer"
    },
    "internal_tool_names": {
      "description": "The list of internal tools to consider during policy generation.",
      "items": {
        "enum": [
          "parse_with_ai",
          "verify_hypothesis",
          "set_policy",
          "complete_turn"
        ],
        "type": "string"
      },
      "title": "Internal Tool Names",
      "type": "array"
    }
  },
  "required": [
    "model",
    "description"
  ],
  "title": "PolicyGenRequestBase",
  "type": "object"
}

Fields:

model pydantic-field

model: str

The model to use for policy generation.

description pydantic-field

description: str

A description of the policy to generate in natural language.

policy_lang pydantic-field

policy_lang: Literal['sqrt'] = 'sqrt'

The policy language to generate the policy in.

n_retries pydantic-field

n_retries: int = 3

The number of times to retry policy generation if it fails or the generated policy is invalid.

internal_tool_names pydantic-field

internal_tool_names: list[InternalToolName]

The list of internal tools to consider during policy generation.

PolicyGenRequestOpenAiChatCompletion pydantic-model

Policy generation request using OpenAI Chat Completions tool format.

Show JSON schema:
{
  "$defs": {
    "FunctionDefinition": {
      "description": "Function definition for tools.",
      "properties": {
        "name": {
          "description": "The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.",
          "title": "Name",
          "type": "string"
        },
        "description": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "A description of what the function does, used by the model to choose when and how to call the function.",
          "title": "Description"
        },
        "parameters": {
          "anyOf": [
            {
              "additionalProperties": true,
              "type": "object"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "The parameters the functions accepts, described as a JSON Schema object.",
          "title": "Parameters"
        },
        "strict": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Whether to enable strict schema adherence when generating the function call.",
          "title": "Strict"
        }
      },
      "required": [
        "name"
      ],
      "title": "FunctionDefinition",
      "type": "object"
    },
    "FunctionTool": {
      "description": "Function tool.",
      "properties": {
        "type": {
          "const": "function",
          "description": "The type of the tool. Currently, only 'function' is supported.",
          "title": "Type",
          "type": "string"
        },
        "function": {
          "$ref": "#/$defs/FunctionDefinition",
          "description": "The function definition."
        }
      },
      "required": [
        "type",
        "function"
      ],
      "title": "FunctionTool",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "Policy generation request using OpenAI Chat Completions tool format.",
  "properties": {
    "model": {
      "description": "The model to use for policy generation.",
      "title": "Model",
      "type": "string"
    },
    "description": {
      "description": "A description of the policy to generate in natural language.",
      "title": "Description",
      "type": "string"
    },
    "policy_lang": {
      "const": "sqrt",
      "default": "sqrt",
      "description": "The policy language to generate the policy in.",
      "title": "Policy Lang",
      "type": "string"
    },
    "n_retries": {
      "default": 3,
      "description": "The number of times to retry policy generation if it fails or the generated policy is invalid.",
      "minimum": 0,
      "title": "N Retries",
      "type": "integer"
    },
    "internal_tool_names": {
      "description": "The list of internal tools to consider during policy generation.",
      "items": {
        "enum": [
          "parse_with_ai",
          "verify_hypothesis",
          "set_policy",
          "complete_turn"
        ],
        "type": "string"
      },
      "title": "Internal Tool Names",
      "type": "array"
    },
    "type": {
      "const": "oai_chat_completion",
      "default": "oai_chat_completion",
      "title": "Type",
      "type": "string"
    },
    "tools": {
      "description": "The list of tools in OpenAI function tool format.",
      "items": {
        "$ref": "#/$defs/FunctionTool"
      },
      "title": "Tools",
      "type": "array"
    }
  },
  "required": [
    "model",
    "description"
  ],
  "title": "PolicyGenRequestOpenAiChatCompletion",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

tools pydantic-field

tools: list[Tool]

The list of tools in OpenAI function tool format.

model pydantic-field

model: str

The model to use for policy generation.

description pydantic-field

description: str

A description of the policy to generate in natural language.

policy_lang pydantic-field

policy_lang: Literal['sqrt'] = 'sqrt'

The policy language to generate the policy in.

n_retries pydantic-field

n_retries: int = 3

The number of times to retry policy generation if it fails or the generated policy is invalid.

internal_tool_names pydantic-field

internal_tool_names: list[InternalToolName]

The list of internal tools to consider during policy generation.

PolicyGenRequestOpenRouterChatCompletion pydantic-model

Policy generation request using OpenRouter Chat Completions tool format.

Show JSON schema:
{
  "$defs": {
    "FunctionDefinition": {
      "description": "Function definition for tools.",
      "properties": {
        "name": {
          "description": "The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.",
          "title": "Name",
          "type": "string"
        },
        "description": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "A description of what the function does, used by the model to choose when and how to call the function.",
          "title": "Description"
        },
        "parameters": {
          "anyOf": [
            {
              "additionalProperties": true,
              "type": "object"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "The parameters the functions accepts, described as a JSON Schema object.",
          "title": "Parameters"
        },
        "strict": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Whether to enable strict schema adherence when generating the function call.",
          "title": "Strict"
        }
      },
      "required": [
        "name"
      ],
      "title": "FunctionDefinition",
      "type": "object"
    },
    "FunctionTool": {
      "description": "Function tool.",
      "properties": {
        "type": {
          "const": "function",
          "description": "The type of the tool. Currently, only 'function' is supported.",
          "title": "Type",
          "type": "string"
        },
        "function": {
          "$ref": "#/$defs/FunctionDefinition",
          "description": "The function definition."
        }
      },
      "required": [
        "type",
        "function"
      ],
      "title": "FunctionTool",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "Policy generation request using OpenRouter Chat Completions tool format.",
  "properties": {
    "model": {
      "description": "The model to use for policy generation.",
      "title": "Model",
      "type": "string"
    },
    "description": {
      "description": "A description of the policy to generate in natural language.",
      "title": "Description",
      "type": "string"
    },
    "policy_lang": {
      "const": "sqrt",
      "default": "sqrt",
      "description": "The policy language to generate the policy in.",
      "title": "Policy Lang",
      "type": "string"
    },
    "n_retries": {
      "default": 3,
      "description": "The number of times to retry policy generation if it fails or the generated policy is invalid.",
      "minimum": 0,
      "title": "N Retries",
      "type": "integer"
    },
    "internal_tool_names": {
      "description": "The list of internal tools to consider during policy generation.",
      "items": {
        "enum": [
          "parse_with_ai",
          "verify_hypothesis",
          "set_policy",
          "complete_turn"
        ],
        "type": "string"
      },
      "title": "Internal Tool Names",
      "type": "array"
    },
    "type": {
      "const": "openrouter_chat_completion",
      "default": "openrouter_chat_completion",
      "title": "Type",
      "type": "string"
    },
    "tools": {
      "description": "The list of tools in OpenRouter function tool format.",
      "items": {
        "$ref": "#/$defs/FunctionTool"
      },
      "title": "Tools",
      "type": "array"
    }
  },
  "required": [
    "model",
    "description"
  ],
  "title": "PolicyGenRequestOpenRouterChatCompletion",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

tools pydantic-field

tools: list[Tool]

The list of tools in OpenRouter function tool format.

model pydantic-field

model: str

The model to use for policy generation.

description pydantic-field

description: str

A description of the policy to generate in natural language.

policy_lang pydantic-field

policy_lang: Literal['sqrt'] = 'sqrt'

The policy language to generate the policy in.

n_retries pydantic-field

n_retries: int = 3

The number of times to retry policy generation if it fails or the generated policy is invalid.

internal_tool_names pydantic-field

internal_tool_names: list[InternalToolName]

The list of internal tools to consider during policy generation.

PolicyGenRequestAnthropicMessages pydantic-model

Policy generation request using Anthropic Messages tool format.

Show JSON schema:
{
  "$defs": {
    "ToolInputSchema": {
      "additionalProperties": true,
      "description": "JSON Schema for tool input parameters.",
      "properties": {
        "type": {
          "const": "object",
          "default": "object",
          "description": "The type of the input schema. Always 'object'.",
          "title": "Type",
          "type": "string"
        },
        "properties": {
          "anyOf": [
            {
              "additionalProperties": true,
              "type": "object"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "The properties of the input schema as a JSON Schema object.",
          "title": "Properties"
        },
        "required": {
          "anyOf": [
            {
              "items": {
                "type": "string"
              },
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "The required properties of the input schema.",
          "title": "Required"
        }
      },
      "title": "ToolInputSchema",
      "type": "object"
    },
    "ToolParam": {
      "description": "Tool definition for the Anthropic Messages API.",
      "properties": {
        "name": {
          "description": "Name of the tool. This is how the tool will be called by the model.",
          "title": "Name",
          "type": "string"
        },
        "input_schema": {
          "anyOf": [
            {
              "$ref": "#/$defs/ToolInputSchema"
            },
            {
              "additionalProperties": true,
              "type": "object"
            }
          ],
          "description": "JSON schema for this tool's input. Defines the shape of the input that the model will produce.",
          "title": "Input Schema"
        },
        "description": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Description of what this tool does. Tool descriptions should be as detailed as possible.",
          "title": "Description"
        },
        "cache_control": {
          "anyOf": [
            {
              "additionalProperties": true,
              "type": "object"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Create a cache control breakpoint at this content block.",
          "title": "Cache Control"
        },
        "strict": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "When true, guarantees schema validation on tool names and inputs.",
          "title": "Strict"
        },
        "type": {
          "anyOf": [
            {
              "const": "custom",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "The type of the tool.",
          "title": "Type"
        }
      },
      "required": [
        "name",
        "input_schema"
      ],
      "title": "ToolParam",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "Policy generation request using Anthropic Messages tool format.",
  "properties": {
    "model": {
      "description": "The model to use for policy generation.",
      "title": "Model",
      "type": "string"
    },
    "description": {
      "description": "A description of the policy to generate in natural language.",
      "title": "Description",
      "type": "string"
    },
    "policy_lang": {
      "const": "sqrt",
      "default": "sqrt",
      "description": "The policy language to generate the policy in.",
      "title": "Policy Lang",
      "type": "string"
    },
    "n_retries": {
      "default": 3,
      "description": "The number of times to retry policy generation if it fails or the generated policy is invalid.",
      "minimum": 0,
      "title": "N Retries",
      "type": "integer"
    },
    "internal_tool_names": {
      "description": "The list of internal tools to consider during policy generation.",
      "items": {
        "enum": [
          "parse_with_ai",
          "verify_hypothesis",
          "set_policy",
          "complete_turn"
        ],
        "type": "string"
      },
      "title": "Internal Tool Names",
      "type": "array"
    },
    "type": {
      "const": "anthropic_messages",
      "default": "anthropic_messages",
      "title": "Type",
      "type": "string"
    },
    "tools": {
      "description": "The list of tools in Anthropic Messages tool format.",
      "items": {
        "$ref": "#/$defs/ToolParam"
      },
      "title": "Tools",
      "type": "array"
    }
  },
  "required": [
    "model",
    "description"
  ],
  "title": "PolicyGenRequestAnthropicMessages",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

tools pydantic-field

tools: list[ToolParam]

The list of tools in Anthropic Messages tool format.

model pydantic-field

model: str

The model to use for policy generation.

description pydantic-field

description: str

A description of the policy to generate in natural language.

policy_lang pydantic-field

policy_lang: Literal['sqrt'] = 'sqrt'

The policy language to generate the policy in.

n_retries pydantic-field

n_retries: int = 3

The number of times to retry policy generation if it fails or the generated policy is invalid.

internal_tool_names pydantic-field

internal_tool_names: list[InternalToolName]

The list of internal tools to consider during policy generation.

PolicyGenRequestOaiResponses pydantic-model

Policy generation request using OpenAI Responses tool format.

.. note:: Not yet supported by the server. Retained for forward compatibility.

Show JSON schema:
{
  "additionalProperties": false,
  "description": "Policy generation request using OpenAI Responses tool format.\n\n.. note:: Not yet supported by the server. Retained for forward compatibility.",
  "properties": {
    "model": {
      "description": "The model to use for policy generation.",
      "title": "Model",
      "type": "string"
    },
    "description": {
      "description": "A description of the policy to generate in natural language.",
      "title": "Description",
      "type": "string"
    },
    "policy_lang": {
      "const": "sqrt",
      "default": "sqrt",
      "description": "The policy language to generate the policy in.",
      "title": "Policy Lang",
      "type": "string"
    },
    "n_retries": {
      "default": 3,
      "description": "The number of times to retry policy generation if it fails or the generated policy is invalid.",
      "minimum": 0,
      "title": "N Retries",
      "type": "integer"
    },
    "internal_tool_names": {
      "description": "The list of internal tools to consider during policy generation.",
      "items": {
        "enum": [
          "parse_with_ai",
          "verify_hypothesis",
          "set_policy",
          "complete_turn"
        ],
        "type": "string"
      },
      "title": "Internal Tool Names",
      "type": "array"
    },
    "type": {
      "const": "oai_responses",
      "default": "oai_responses",
      "title": "Type",
      "type": "string"
    },
    "tools": {
      "description": "The list of tools in OpenAI Responses format.",
      "items": {
        "additionalProperties": true,
        "type": "object"
      },
      "title": "Tools",
      "type": "array"
    }
  },
  "required": [
    "model",
    "description"
  ],
  "title": "PolicyGenRequestOaiResponses",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

tools pydantic-field

tools: list[dict[str, Any]]

The list of tools in OpenAI Responses format.

model pydantic-field

model: str

The model to use for policy generation.

description pydantic-field

description: str

A description of the policy to generate in natural language.

policy_lang pydantic-field

policy_lang: Literal['sqrt'] = 'sqrt'

The policy language to generate the policy in.

n_retries pydantic-field

n_retries: int = 3

The number of times to retry policy generation if it fails or the generated policy is invalid.

internal_tool_names pydantic-field

internal_tool_names: list[InternalToolName]

The list of internal tools to consider during policy generation.

PolicyGenRequestSequrityAzureChatCompletion pydantic-model

Policy generation request using Sequrity Azure Chat Completions tool format.

Show JSON schema:
{
  "$defs": {
    "FunctionDefinition": {
      "description": "Function definition for tools.",
      "properties": {
        "name": {
          "description": "The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.",
          "title": "Name",
          "type": "string"
        },
        "description": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "A description of what the function does, used by the model to choose when and how to call the function.",
          "title": "Description"
        },
        "parameters": {
          "anyOf": [
            {
              "additionalProperties": true,
              "type": "object"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "The parameters the functions accepts, described as a JSON Schema object.",
          "title": "Parameters"
        },
        "strict": {
          "anyOf": [
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Whether to enable strict schema adherence when generating the function call.",
          "title": "Strict"
        }
      },
      "required": [
        "name"
      ],
      "title": "FunctionDefinition",
      "type": "object"
    },
    "FunctionTool": {
      "description": "Function tool.",
      "properties": {
        "type": {
          "const": "function",
          "description": "The type of the tool. Currently, only 'function' is supported.",
          "title": "Type",
          "type": "string"
        },
        "function": {
          "$ref": "#/$defs/FunctionDefinition",
          "description": "The function definition."
        }
      },
      "required": [
        "type",
        "function"
      ],
      "title": "FunctionTool",
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "Policy generation request using Sequrity Azure Chat Completions tool format.",
  "properties": {
    "model": {
      "description": "The model to use for policy generation.",
      "title": "Model",
      "type": "string"
    },
    "description": {
      "description": "A description of the policy to generate in natural language.",
      "title": "Description",
      "type": "string"
    },
    "policy_lang": {
      "const": "sqrt",
      "default": "sqrt",
      "description": "The policy language to generate the policy in.",
      "title": "Policy Lang",
      "type": "string"
    },
    "n_retries": {
      "default": 3,
      "description": "The number of times to retry policy generation if it fails or the generated policy is invalid.",
      "minimum": 0,
      "title": "N Retries",
      "type": "integer"
    },
    "internal_tool_names": {
      "description": "The list of internal tools to consider during policy generation.",
      "items": {
        "enum": [
          "parse_with_ai",
          "verify_hypothesis",
          "set_policy",
          "complete_turn"
        ],
        "type": "string"
      },
      "title": "Internal Tool Names",
      "type": "array"
    },
    "type": {
      "const": "sequrity_azure_chat_completion",
      "default": "sequrity_azure_chat_completion",
      "title": "Type",
      "type": "string"
    },
    "tools": {
      "description": "The list of tools in Sequrity Azure function tool format.",
      "items": {
        "$ref": "#/$defs/FunctionTool"
      },
      "title": "Tools",
      "type": "array"
    }
  },
  "required": [
    "model",
    "description"
  ],
  "title": "PolicyGenRequestSequrityAzureChatCompletion",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

tools pydantic-field

tools: list[Tool]

The list of tools in Sequrity Azure function tool format.

model pydantic-field

model: str

The model to use for policy generation.

description pydantic-field

description: str

A description of the policy to generate in natural language.

policy_lang pydantic-field

policy_lang: Literal['sqrt'] = 'sqrt'

The policy language to generate the policy in.

n_retries pydantic-field

n_retries: int = 3

The number of times to retry policy generation if it fails or the generated policy is invalid.

internal_tool_names pydantic-field

internal_tool_names: list[InternalToolName]

The list of internal tools to consider during policy generation.

PolicyGenRequestSequrityAzureResponses pydantic-model

Policy generation request using Sequrity Azure Responses tool format.

Show JSON schema:
{
  "additionalProperties": false,
  "description": "Policy generation request using Sequrity Azure Responses tool format.",
  "properties": {
    "model": {
      "description": "The model to use for policy generation.",
      "title": "Model",
      "type": "string"
    },
    "description": {
      "description": "A description of the policy to generate in natural language.",
      "title": "Description",
      "type": "string"
    },
    "policy_lang": {
      "const": "sqrt",
      "default": "sqrt",
      "description": "The policy language to generate the policy in.",
      "title": "Policy Lang",
      "type": "string"
    },
    "n_retries": {
      "default": 3,
      "description": "The number of times to retry policy generation if it fails or the generated policy is invalid.",
      "minimum": 0,
      "title": "N Retries",
      "type": "integer"
    },
    "internal_tool_names": {
      "description": "The list of internal tools to consider during policy generation.",
      "items": {
        "enum": [
          "parse_with_ai",
          "verify_hypothesis",
          "set_policy",
          "complete_turn"
        ],
        "type": "string"
      },
      "title": "Internal Tool Names",
      "type": "array"
    },
    "type": {
      "const": "sequrity_azure_responses",
      "default": "sequrity_azure_responses",
      "title": "Type",
      "type": "string"
    },
    "tools": {
      "description": "The list of tools in Sequrity Azure Responses format.",
      "items": {
        "additionalProperties": true,
        "type": "object"
      },
      "title": "Tools",
      "type": "array"
    }
  },
  "required": [
    "model",
    "description"
  ],
  "title": "PolicyGenRequestSequrityAzureResponses",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

tools pydantic-field

tools: list[dict[str, Any]]

The list of tools in Sequrity Azure Responses format.

model pydantic-field

model: str

The model to use for policy generation.

description pydantic-field

description: str

A description of the policy to generate in natural language.

policy_lang pydantic-field

policy_lang: Literal['sqrt'] = 'sqrt'

The policy language to generate the policy in.

n_retries pydantic-field

n_retries: int = 3

The number of times to retry policy generation if it fails or the generated policy is invalid.

internal_tool_names pydantic-field

internal_tool_names: list[InternalToolName]

The list of internal tools to consider during policy generation.


Response Types

PolicyGenResponse pydantic-model

Response from the policy generation endpoint.

Contains the generated SQRT policy code and token usage statistics.

Show JSON schema:
{
  "additionalProperties": false,
  "description": "Response from the policy generation endpoint.\n\nContains the generated SQRT policy code and token usage statistics.",
  "properties": {
    "policies": {
      "description": "The generated policy or policies in the specified policy language.",
      "title": "Policies",
      "type": "string"
    },
    "usage": {
      "additionalProperties": {
        "type": "integer"
      },
      "description": "Token usage for the policy generation request.",
      "title": "Usage",
      "type": "object"
    }
  },
  "required": [
    "policies",
    "usage"
  ],
  "title": "PolicyGenResponse",
  "type": "object"
}

Config:

  • extra: forbid

Fields:

policies pydantic-field

policies: str

The generated policy or policies in the specified policy language.

usage pydantic-field

usage: dict[str, int]

Token usage for the policy generation request.