Pulastya B commited on
Commit
f34a4e8
·
1 Parent(s): 109a48b

CRITICAL FIX: Sanitize corrupted tool names from Mistral API

Browse files

- Added validation to check tool_name length and format
- Regex extraction to recover actual tool name from garbled responses
- Skip tool calls that cannot be recovered
- Prevents garbled tool names like 'Error Analysis: ...ewódhyperparameter_tuning'

Files changed (1) hide show
  1. src/orchestrator.py +16 -0
src/orchestrator.py CHANGED
@@ -2428,6 +2428,22 @@ You are a DOER. Complete workflows based on user intent."""
2428
  tool_name = tool_call.function.name
2429
  tool_args = json.loads(tool_call.function.arguments)
2430
  tool_call_id = tool_call.id
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2431
  elif self.provider == "gemini":
2432
  tool_name = tool_call.name
2433
  # Convert protobuf args to Python dict
 
2428
  tool_name = tool_call.function.name
2429
  tool_args = json.loads(tool_call.function.arguments)
2430
  tool_call_id = tool_call.id
2431
+
2432
+ # CRITICAL FIX: Sanitize tool_name (API sometimes returns garbage)
2433
+ # Tool names should be simple alphanumeric + underscore only
2434
+ if not isinstance(tool_name, str) or len(tool_name) > 100:
2435
+ print(f"⚠️ CORRUPTED TOOL NAME DETECTED: {str(tool_name)[:200]}")
2436
+ # Try to extract actual tool name from garbage
2437
+ import re
2438
+ # Look for valid tool name pattern at the end
2439
+ match = re.search(r'([a-z_]+)[\"\']?\s*$', str(tool_name), re.IGNORECASE)
2440
+ if match:
2441
+ tool_name = match.group(1)
2442
+ print(f"✓ Recovered tool name: {tool_name}")
2443
+ else:
2444
+ print(f"❌ Cannot recover tool name, skipping this tool call")
2445
+ continue
2446
+
2447
  elif self.provider == "gemini":
2448
  tool_name = tool_call.name
2449
  # Convert protobuf args to Python dict