Skip to content

fix: unwrap singleton array in tryParseStructuredJsonValue#22

Open
gianellichia980-png wants to merge 2 commits intoExplosiveCoderflome:mainfrom
gianellichia980-png:main
Open

fix: unwrap singleton array in tryParseStructuredJsonValue#22
gianellichia980-png wants to merge 2 commits intoExplosiveCoderflome:mainfrom
gianellichia980-png:main

Conversation

@gianellichia980-png
Copy link
Copy Markdown

@gianellichia980-png gianellichia980-png commented Apr 15, 2026

Summary

Two bug fixes for the structured JSON output pipeline:

Fix 1: unwrap singleton array in tryParseStructuredJsonValue

When the LLM returns structured JSON wrapped in a singleton array like [{"goal":"..."}], extractJSONValue extracts the whole array because [ appears before {. JSON.parse succeeds but Zod schema validation fails because the schema expects an object, not an array.

Added unwrapSingletonArray() helper that automatically unwraps single-element arrays after parsing.

Fixes #10

Fix 2: detect HTML error pages from relays as transport_error

When using a relay/proxy (中转站), the connectivity probe fails with "malformed_json" error category even when the relay returned HTML (e.g. 429 rate limit page, 403 auth error page) rather than JSON.

Added HTML response detection in classifyStructuredOutputFailure. When the error message contains HTML tags or common relay error indicators, classify it as transport_error instead of malformed_json.

Fixes #15

Files changed

  • server/src/llm/structuredInvoke.ts: Added unwrapSingletonArray() function
  • server/src/llm/structuredOutput.ts: Added HTML detection in classifyStructuredOutputFailure

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