Skip to content

Commit 268fa4d

Browse files
committed
add more fields
1 parent 132c3cc commit 268fa4d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

docs/guardrails/code-validation.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,33 @@ def python_code(
105105
) -> List[str]
106106
```
107107

108-
Parses provided Python code and returns a `PythonDetectorResult` object containing the following fields:
108+
Parses provided Python code and returns a `PythonDetectorResult` object.
109+
110+
**Parameters**
111+
112+
| Name | Type | Description |
113+
|-------------|--------|----------------------------------------|
114+
| `data` | `str | list | dict` | The Python code to be parsed. |
115+
| `ipython_mode` | `bool` | If set to <span class='boolean-value-true'>TRUE</span>, the code will be parsed in IPython mode. This is useful for parsing code that uses IPython-specific features or syntax. |
116+
117+
**Returns**
118+
119+
| Type | Description |
120+
|--------|----------------------------------------|
121+
| `PythonDetectorResult` | The result of the detector. |
122+
123+
124+
### `PythonDetectorResult` objects
125+
`PythonDetectorResult` objects represent the analysis results of a Python code snippet.
126+
127+
| Name | Type | Description |
128+
|-------------|--------|----------------------------------------|
129+
| `.imports` | `list[str]` | This field contains a list of imported modules in the provided code. It is useful for identifying which libraries or modules are being used in the code. |
130+
| `.builtins` | `list[str]` | A list of built-in functions used in the provided code. |
131+
| `.syntax_error` | `bool` | A boolean flag indicating whether the provided code has syntax errors. |
132+
| `.syntax_error_exception` | `str | None` | A string containing the exception message if a syntax error occurred while parsing the provided code. |
133+
| `.function_calls` | `set[str]` | A set of function call identifier names in the provided code. |
134+
109135
## Static Code Analysis
110136

111137
Static code analysis allows for powerful pattern-based detection of vulnerabilities and insecure coding practices. Invariant integrates [Semgrep](https://semgrep.dev) directly into your guardrails, enabling deep analysis of assistant-generated code before it's executed.

0 commit comments

Comments
 (0)