Skip to content

Commit dcda92e

Browse files
committed
Improve safety
1 parent 3cc654c commit dcda92e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

deepfabric/formatters/builtin/trl_sft_tools.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,15 @@ def _convert_agent_to_messages(
216216
# Parse tool input
217217
if isinstance(tool_input, str):
218218
try:
219-
tool_args = json.loads(tool_input.replace("'", '"'))
220-
except (json.JSONDecodeError, AttributeError):
221-
tool_args = {"input": tool_input}
219+
# First try parsing as standard JSON
220+
tool_args = json.loads(tool_input)
221+
except json.JSONDecodeError:
222+
try:
223+
# Fallback: try replacing single quotes with double quotes
224+
tool_args = json.loads(tool_input.replace("'", '"'))
225+
except json.JSONDecodeError:
226+
# Final fallback: wrap in a simple structure
227+
tool_args = {"input": tool_input}
222228
else:
223229
tool_args = tool_input
224230

0 commit comments

Comments
 (0)