From 09b0b05c317eb7d49ad9a7ee96ea22f2d4acb1f3 Mon Sep 17 00:00:00 2001 From: Benedictus Reynaldo Hartanto Date: Fri, 4 Sep 2026 19:47:43 +0900 Subject: [PATCH] fix(google): steer Google models away from unrendered LaTeX math formatting Google-family models (Gemini/Antigravity/Vertex) frequently wrap coordinates, dimensions, variables, and math in LaTeX math delimiters ($...$, ..., (...), ext{}, etc.). Because Codex Desktop renders standard Markdown without KaTeX support, these delimiters show up as raw unrendered LaTeX strings in chat output. Include explicit client formatting guidance in GOOGLE_BREVITY_INSTRUCTION so Google models output clean Markdown, plain text, and Unicode symbols instead. --- src/adapters/google.ts | 1 + tests/adapters/google/google-adapter.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/adapters/google.ts b/src/adapters/google.ts index 7af5bbdbf1..9d828af0bd 100644 --- a/src/adapters/google.ts +++ b/src/adapters/google.ts @@ -52,6 +52,7 @@ const GOOGLE_BREVITY_INSTRUCTION = [ "- Do detailed reasoning internally, not as visible intermediate output.", "- Prefer taking the next tool action over explaining; keep calling tools until the task is complete.", "- This applies only to intermediate progress text. Your final answer after the work is done is exempt: write it in full and at whatever length the task requires.", + "- Formatting: The client environment renders standard Markdown and does not support LaTeX math delimiters ($...$, $$...$$, \\(...\\), \\[...\\]). Do not use LaTeX math delimiters or LaTeX markup (such as \\text{}, \\times, \\le, \\ge, etc.) for variables, formulas, dimensions, or units. Use clean plain text, Markdown, and Unicode symbols (e.g. 180°, 2560 × 1920 px, ≤, ≥, Δ, ±) instead.", ].join("\n"); const ANTIGRAVITY_REJECTED_CLAUDE_SDK_PARAGRAPH = diff --git a/tests/adapters/google/google-adapter.test.ts b/tests/adapters/google/google-adapter.test.ts index 80ad0e9f4c..61e1d15d4b 100644 --- a/tests/adapters/google/google-adapter.test.ts +++ b/tests/adapters/google/google-adapter.test.ts @@ -174,6 +174,16 @@ describe("google adapter — tool-call ids on the wire", () => { expect(instruction.parts[0].text).toContain("Valid tool names for this turn are exactly `exec_command`."); }); + test("systemInstruction includes formatting guidance against unrendered LaTeX math", async () => { + const body = await geminiBody(parsedWith( + [{ role: "user", content: "inspect results" }], + [], + )); + const instruction = body.systemInstruction as { parts: Array<{ text: string }> }; + expect(instruction.parts[0].text).toContain(String.raw`does not support LaTeX math delimiters ($...$, $$...$$, \(...\), \[...\])`); + expect(instruction.parts[0].text).toContain(String.raw`\text{}, \times, \le, \ge`); + }); + test("functionCall and functionResponse carry the matching tool-call id", async () => { const contents = await geminiContents(parsedWith([ { role: "assistant", content: [{ type: "toolCall", id: "call_abc", name: "bash", arguments: { cmd: "ls" } }] },