nemoguardrails.utils
Module Contents
Classes
Functions
Data
API
Bases: SafeDumper
Bases: JSONEncoder
Custom json encoder to handler dataclass and enum types
Add modality related information to the action event
Update action related even properties and ensure UMIM compliance (very basic)
Converts a CamelCase string to snake_case.
Parameters:
The CamelCase string to convert.
Returns: str
The converted snake_case string.
Check if an object’s nesting depth exceeds the maximum allowed depths
Parameters:
the object to check
current nesting depth
Raises:
ValueError: if the object is too deeply nested
Return the hash of the given text using MD5 if available, otherwise use SHA256.
Parameters:
The input text to hash.
Returns: str
The hexadecimal digest of the hash.
Performs basic event validation and throws an AssertionError if any of the validators fail.
Safely extracts the JSON part from the exception message
Parameters:
The exception message.
Returns: dict
The extracted JSON part as a dictionary, or an error dictionary if extraction fails.
Helper to get the path to the data directory.
Helper to get the path to the examples data directory.
Helper to return the current asyncio loop.
If one does not exist, it will be created.
Get railsignore path.
Parameters:
The starting path to search for the .railsignore file.
Returns: Optional[Path]
The .railsignore file path, if found.
Raises:
FileNotFoundError: If the .railsignore file is not found.
Retrieve all specified patterns in railsignore.
Returns: Set[str]
Set[str]: The set of filenames or glob patterns in railsignore
Init random generator with seed.
Verify if a filename should be ignored by a railsignore pattern
Performs a basic event validation and returns True if the event conforms.
Helper to create a generic event structure.
Creates a new uuid with a human readable prefix.
Helper to generate new UUID v4.
In testing mode, it will generate a predictable set of UUIDs to help debugging if random seed was set dependent on the environment variable DEBUG_MODE.
Creates a new uuid that is compatible with variable names.
Safely evaluate a string to handle unescaped quotes or invalid syntax from the async generate_value action.
Parameters:
The input string to evaluate.
Returns: str
The evaluated and properly formatted string.
Raises:
ValueError: If the input cannot be safely evaluated.
Converts a snake_case string to CamelCase.
Parameters:
The snake_case string to convert.
Returns: str
The converted CamelCase string.