src.tools.core.parsers.json_tool_call_parser.JSONToolCallParser
Bases: BaseToolCallParser
Enhanced parser for extracting and processing JSON tool calls from raw text.
This parser handles common LLM JSON generation errors including:
- Semicolons instead of commas between array items
- Missing or extra commas
- Unquoted keys
- Single quotes instead of double quotes
- Trailing commas
- Other common JSON syntax errors
Source code in src/tools/core/parsers/json_tool_call_parser.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
extract(text)
Extract and parse JSON tool calls from the input text with enhanced error recovery.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The input text containing JSON tool calls. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing parsed tool calls or error information. |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Source code in src/tools/core/parsers/json_tool_call_parser.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
find_json_content(text)
staticmethod
Extract potential JSON content from raw text using balanced delimiter matching.
This method scans the text character by character to identify and extract valid JSON objects or arrays, handling nested structures correctly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The raw text to search for JSON content. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of extracted JSON string segments. |
Source code in src/tools/core/parsers/json_tool_call_parser.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
parse_nested_json(value)
Recursively parses stringified JSON within a JSON structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
The input value to check and potentially parse. |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The processed value, either as a parsed JSON object or as its original type. |
Source code in src/tools/core/parsers/json_tool_call_parser.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
preprocess_json(json_str)
Preprocess JSON string to fix common LLM-generated syntax errors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_str
|
str
|
The potentially malformed JSON string. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A corrected JSON string. |
Source code in src/tools/core/parsers/json_tool_call_parser.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
split_json_list_items(json_list)
Split a JSON array string into individual item strings for separate parsing.
This handles cases where items are separated by semicolons or have other issues.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_list
|
str
|
A string containing a JSON array with possibly invalid separators. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of individual item strings. |
Source code in src/tools/core/parsers/json_tool_call_parser.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|