v0.8.3: fix SQL double-wrap bug in Thinker tool parsing
Python code blocks containing SQL keywords (SELECT, CREATE) were incorrectly re-wrapped in the SQL template. Now only blocks explicitly tagged as sql/sqlite get wrapped. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
231f81bc52
commit
4e2cd4ed59
@ -63,11 +63,13 @@ You can combine text + code + controls in one response.
|
|||||||
continue
|
continue
|
||||||
return (tool_name, "\n".join(code_lines)) if code_lines else None
|
return (tool_name, "\n".join(code_lines)) if code_lines else None
|
||||||
|
|
||||||
block_match = re.search(r'```(?:python|py|sql|sqlite|sh|bash|tool_code)?\s*\n(.*?)```', text, re.DOTALL)
|
block_match = re.search(r'```(python|py|sql|sqlite|sh|bash|tool_code)?\s*\n(.*?)```', text, re.DOTALL)
|
||||||
if block_match:
|
if block_match:
|
||||||
code = block_match.group(1).strip()
|
lang = (block_match.group(1) or "").lower()
|
||||||
|
code = block_match.group(2).strip()
|
||||||
if code and len(code.split("\n")) > 0:
|
if code and len(code.split("\n")) > 0:
|
||||||
if "```sql" in text or "```sqlite" in text or ("SELECT" in code.upper() and "CREATE" in code.upper()):
|
# Only wrap raw SQL blocks — never re-wrap python that happens to contain SQL keywords
|
||||||
|
if lang in ("sql", "sqlite"):
|
||||||
wrapped = f'''import sqlite3
|
wrapped = f'''import sqlite3
|
||||||
conn = sqlite3.connect("/tmp/cog_db.sqlite")
|
conn = sqlite3.connect("/tmp/cog_db.sqlite")
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user