To configure the AI Custom Guardrail plugin to work with your guardrail service, you must define your Service’s required parameters under config.params. They key will be the parameter name, and the value can be a string or a Lua expression.
Additionally, the following built-in variables are available in Lua expression. They can be used as arguments in functions, but not in the function body:
The config.request field is used to configure the request that will be sent to your guardrail service. You can set the URL, request body, headers, query parameters, and authentication. You can use the parameters defined under config.params using the following syntax: $(conf.params.<PARAM_KEY>).
The config.response field is used to define how to parse the response received by the guardrail service. You must define:
These fields can be defined using functions defined in config.functions, Lua expressions, or strings. For example, to use the value of a field named action in the guardrail service’s response body, you can set config.response.block to $(resp.action).
The config.metrics field allows you to define metrics to be logged by Kong Gateway. The following standard metrics are available:
-
block_reason: The reason why the request or response was blocked.
-
block_details: Additional details about the blocked request or response.
-
masked: Whether content was masked in the request or response.
The values can be set to Lua expressions. You can also use the config.custom_metrics field to define additional metrics.