Skip to content

Create a Guardrail Function

See the Python handler definition for general handler structure and the Guardrail handler definition for ExtProc-specific behavior.

Parameters

Name Type Required Description
project str (✓) Project name. Required only when creating from the library; otherwise MUST NOT be set.
name str ✓ Name that identifies the object.
kind str ✓ Function kind. Must be guardrail.
uuid str Object ID in UUID4 format.
description str Description of the object.
labels list[str] List of labels.
embedded bool Whether the object should be embedded in the project.
code_src str URI pointing to the source code.
code str Source code provided as plain text.
base64 str Source code encoded as base64.
handler str Function entrypoint.
init_function str Init function name for remote execution.
python_version str ✓ Execution Python version.
lang str Source code language (informational).
image str Container image used to execute the function.
base_image str Base image (name:tag) used when building the execution image.
requirements list[str] | str Pip requirements or a supported requirements file.
processing_mode str ✓ Mode: preprocessor, postprocessor, or wrapprocessor.

Example

function = dh.new_function(
    name="request-guardrail",
    kind="guardrail",
    code_src="guardrail.py",
    handler="process",
    python_version="PYTHON3_10",
    processing_mode="preprocessor",
)