Documentation
¶
Overview ¶
Package llmwrap holds JSON-extraction and truncation helpers shared across the LLM-wrapping components of the ADR-045 Phase 1 research- graph chain (route_search, assess_sufficiency, synthesize_answer).
Scope is deliberately small: extracting a balanced JSON object out of a model's response (markdown fences + prose preface), and capping a string at N bytes with an ellipsis suffix for error-line readability. The chat-completion adapter stays per-component so each component can keep a narrowly-purposed Router/Assessor/ Synthesizer interface in its handler; only the response-shape helpers live here.
Promoted to a shared package in ADR-045 Phase 1 PR 5 (the second and third LLM-wrapping components). Previously inlined in processor/research-graph-route/handler.go; that copy is removed in the same PR.
Index ¶
Constants ¶
const ErrPayloadTruncateBytes = 512
ErrPayloadTruncateBytes caps the raw-payload snippet rendered in error messages. 512 keeps the structured-emit JSON's action enum, per-action arg keys, and short rationales visible even when the model wrapped its emit in long prose.
Variables ¶
This section is empty.
Functions ¶
func ExtractJSON ¶
ExtractJSON pulls a balanced JSON object out of an LLM response. Many models wrap structured emits in ```json fences or prose preface; this helper strips fences, then walks the first balanced {...} substring while tracking JSON string-literal context (so a `}` inside a string value, e.g. a rationale field like "axes spanning {time, entity_type}", does not truncate the extraction mid-object). Backslash-escaped quotes inside strings do not toggle the string-context flag.
Returns an error if the trimmed content contains no `{`, or if the balanced-brace walker reaches end-of-input with unmatched depth.
Types ¶
This section is empty.