nemoguardrails.llm.completion_parsing

View as Markdown

Text helpers for interpreting raw LLM completions.

Pure string transformations with no Colang, event, or configuration dependency, so they can be used from a rail action that runs without a Colang runtime.

The completion parsers that do depend on Colang intent/action vocabulary stay in nemoguardrails.actions.llm.utils.

Module Contents

Functions

NameDescription
get_multiline_responseHelper that extracts multi-line responses from the LLM.
remove_action_intent_identifiersRemoves the action/intent identifiers.
strip_quotesHelper that removes quotes from a string if the entire string is between quotes

API

nemoguardrails.llm.completion_parsing.get_multiline_response(
s: str
) -> str

Helper that extracts multi-line responses from the LLM. Stopping conditions: when a non-empty line ends with a quote or when the token “user” appears after a newline. Empty lines at the begging of the string are skipped.

nemoguardrails.llm.completion_parsing.remove_action_intent_identifiers(
lines: typing.List[str]
) -> typing.List[str]

Removes the action/intent identifiers.

nemoguardrails.llm.completion_parsing.strip_quotes(
s: str
) -> str

Helper that removes quotes from a string if the entire string is between quotes