Input Rails
This section explains how to create input rails in Colang 2.0.
Definition
Input Rails are a type of rail that checks the input from the user (i.e., what the user said) before any further processing.
Usage
To activate input rails in Colang 2.0, you must:
- Import the
guardrailsmodule from the Colang Standard Library (CSL). - Define a flow called
input rails, which takes a single parameter called$input_text.
In the example below, the input rails flow calls another flow named check user message which prompts the LLM to check the input.
examples/v2_x/tutorial/guardrails_1/main.co
The input rails flow above (lines 19-24) introduces some additional syntax elements:
- Starting flow parameters and variables with a
$symbol, e.g.$input_text,$input_safe. - Using the
awaitoperator to wait for another flow. - Capturing the return value of a flow using a local variable, e.g.,
$input_safe = await check user utterance $input_text. - Using
if, similar to Python. - Using the
abortkeyword to make a flow fail.
The check user utterance flow above (line 26-28) introduces the instruction operator i"<instruction>"" which will prompt the LLM to generate the value True or False depending on the evaluated safety of the user utterance. In line 28, the generated value assigned to $is_safe will be returned.
Testing
The next example will show you how to create a simple interaction loop.