altimate-code icon indicating copy to clipboard operation
altimate-code copied to clipboard

answer_commit rejects call: model sends `fields` as a JSON string ("expected array, received string")

Open ekkundia-build opened this issue 3 weeks ago • 0 comments

Version: altimate-code 0.12.10 (npm), macOS arm64 Model: Altimate Base Mode: Analyst Project: small dbt + DuckDB project (jaffle_shop)

What happened

Prompt: "Order counts on the customers model look high. Is anything wrong?"

Reproduced in two separate sessions. Both times the analyst found the right answer (a join fan-out: 113 counted vs 99 actual orders), then every answer_commit call was rejected, and the agent fell back to plain text:

  • Run 1: 4 attempts with fields + asked + basis, the last shaped like the tool's own minimal example.
  • Run 2: 3 attempts with only fields (one entry) + basis.

Cause (confirmed with /trace)

Every rejection is the same:

ToolInvalidArgumentsError: The answer_commit tool was called with invalid arguments:
fields: Invalid input: expected array, received string
Minimal valid example: `{"fields":[{"name":"","value":2}],"basis":"Counted all records at record grain using records.id; no exclusions."}`
Please rewrite the input so it satisfies the expected schema.

Altimate Base sends fields as a JSON-encoded string ("[{...}]") instead of an array. The content is valid, but z.array(...) rejects it. The retry hint doesn't help the model recover, so it fails the same way each time.

Expected

The structured answer commits on the first or second try.

Impact

In run 2: 11m49s, 15 LLM calls and ~544k tokens for a read-only question, and the structured, checked answer was lost at the end.

Suggested fix

In the z.preprocess in src/altimate/tools/answer-commit.ts (which today only normalizes answer_only), parse string values of fields, rows, asked and unresolved with JSON.parse when they look like a JSON array or object, before validation. That accepts this model's output without loosening the schema.

Also seen in the same sessions

sql_execute failed in both runs because the DuckDB driver is missing its native binding:

Cannot find module '~/.local/share/altimate-code/drivers/node_modules/duckdb/lib/binding/duckdb.node'

That's why the agent read the seed CSVs instead of querying. Likely related to #1193.

Related

#1582, #1531, #1481, #1193

ekkundia-build avatar Nov 09 '26 13:11 ekkundia-build