Skip to content

Comments

Add autofix extension for malformed JSON tool calls#1

Draft
clebreto wants to merge 1 commit intoben-vargas:mainfrom
clebreto:main
Draft

Add autofix extension for malformed JSON tool calls#1
clebreto wants to merge 1 commit intoben-vargas:mainfrom
clebreto:main

Conversation

@clebreto
Copy link

Autofix Extension for Malformed JSON

Automatically fixes broken JSON in tool calls using Synthetic's hf:syntheticlab/fix-json model.

Why?

Some models generate malformed JSON (missing quotes, trailing commas, etc). This extension catches those errors and fixes them automatically, so tool calls don't fail.

Quick Start

export SYNTHETIC_API_KEY="syn_..."
pi -e ./extensions/autofix.ts

Then use /test-autofix to try it out.

How It Works

Uses the new onToolCallParse hook from https://github.com/clebreto/pi-mono/pull/feature/hook-based-tool-parsing:

  1. Intercepts JSON before parsing
  2. Tries normal parse first
  3. If that fails, sends to fix model
  4. Returns fixed JSON

Config

  • PI_AUTOFIX_ENABLED - turn on/off (default: true)
  • PI_AUTOFIX_MODEL - which model to use (default: hf:syntheticlab/fix-json)
  • SYNTHETIC_API_KEY - your API key

Files Changed

  • extensions/autofix.ts (new) - the extension
  • package.json - register the extension

IT MUST REMAIN IN DRAFT SO LONG THE PR IN PI-MONO IS NOT MERGED.

This extension provides automatic fixing of malformed JSON tool calls
using the Synthetic fix-json model.

Features:
- Intercepts tool call JSON parsing via onToolCallParse hook
- Fixes malformed JSON using hf:syntheticlab/fix-json
- Shows "Fixing JSON for {toolName}..." in working message during fix
- Includes /test-autofix command for testing

Setup:
  export SYNTHETIC_API_KEY="syn_..."
  pi -e ./extensions/autofix.ts

Configuration:
  PI_AUTOFIX_ENABLED - Enable/disable (default: true)
  PI_AUTOFIX_MODEL - Fix model (default: hf:syntheticlab/fix-json)
  PI_AUTOFIX_BASE_URL - API endpoint

Requires pi with hook-based tool parsing support.
Related: PR feature/hook-based-tool-parsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant