symfonic.agent.middleware.fabrication¶
fabrication ¶
Fabrication-verdict executor (v7.0 T10, patched v7.0.3, v7.0.6).
v6.1.10 shipped TOOL DISCIPLINE at the prompt tier — telling the LLM not to invent task IDs, PIDs, or tool outputs. T10 adds the executor-side counterpart so a non-compliant LLM is still caught.
The detector scans the response draft for tool-call-shaped prose:
phrases like "I ran", "I called", "task_id=", "PID=", UUID patterns,
and any key listed in DomainTemplate.identifier_keys. For each
candidate identifier it cross-references:
- Tool results captured for this turn (
LLMPreCallEvent/on_llm_endfan-outs). - Hydrated semantic node properties injected in the system prompt.
- The user message verbatim.
Unresolved identifiers produce a FabricationFinding with a
confidence score. Callers decide whether to downgrade, revise, or
refuse based on FrameworkConfig.fabrication_check_mode.
Zero-cost contract: when the draft is empty, tool_calls_this_turn
is empty, and no identifier_keys are configured, the detector
returns an empty list after a single regex pre-filter.
v7.0.3 patches (F1, F2):
- F1 short-hex detector. The canonical-UUID-only pattern let
8-16-hex-char fakes like
9f2b1e47slip through when the LLM decided a "prettier" identifier looked more plausible. A new_SHORT_HEX_PATTERNfires only in anchored contexts -- within ~60 chars of a claim verb match, or immediately after a known identifier key (task_id=,pid=, ...). Short-hex findings carryconfidence=0.6so the refuse-mode threshold can gate them while observe-mode still logs telemetry. Full-UUID findings keepconfidence=0.95-- well above the refuse threshold. - F2 per-verb tool-call grounding. Previously a single tool
call anywhere in the turn silenced every verb-claim finding. Now
each verb-claim finding consults
_VERB_TO_TOOL_HINTSand is dropped only when a tool whose name matches the verb's expected pattern actually fired. This catches the real-world case wherehydrate_contextran but the response still claims "I spawned subagent X" withoutspawn_subagenthaving executed.
v7.0.6 patch — language-agnostic intent_action_no_tool finding:
_CLAIM_VERB_PATTERNis intentionally English-only ("I ran", "I sent", ...). Spanish passive ("Gráfica enviada"), French ("J'ai envoyé"), German separable verbs, and Portuguese third-person all bypass it. Adding per-locale verb lexicons compounds technical debt — combinatorial growth, grammar coupling, drift from the actual concern.
v7.0.6 reuses the already-computed IntentVerdict (from
v7.0 T07 + v7.0.3 F3 Unicode tokenizer + DomainTemplate.
tool_trigger_keywords) instead. When the verdict says
label="action" AND tool_calls_this_turn is empty, the
LLM promised a side-effect and produced none, regardless of
language. The classifier already does the i18n work — the
detector just consumes the verdict. Zero extra latency: the same
verdict that drove intent_filter / tool_routing this turn is
threaded into the detector via apply_fabrication_check.
When neither knob is enabled, intent_verdict is None and
the new finding never fires (back-compat).
Confidence is 0.7 — below the default
fabrication_refuse_min_confidence=0.8 so v7.0.6 ships in
observe / revise friendly form. Operators dial the threshold
to 0.65 to opt into refuse-mode draft replacement on the new
finding kind.
FabricationFinding
dataclass
¶
FabricationFinding(
identifier: str,
kind: FabricationKind,
severity: FabricationSeverity,
reason: str,
key: str | None = None,
pattern_kind: str = "",
confidence: float = 0.8,
span: tuple[int, int] = (0, 0),
grounded_sources: list[str] = list(),
)
A single flagged identifier in the response draft.
Attributes:
| Name | Type | Description |
|---|---|---|
identifier |
str
|
The literal token the LLM claimed was real. |
kind |
FabricationKind
|
|
severity |
FabricationSeverity
|
Heuristic severity; callers gate on this via
|
reason |
str
|
Short human-readable explanation. |
key |
str | None
|
When |
pattern_kind |
str
|
Stable lowercase string mirror of |
confidence |
float
|
0.0-1.0 detection confidence. v7.0.3 uses 0.95 for
canonical UUIDs, 0.6 for context-anchored short-hex, and
0.8 for kv / verb_claim (the v7.0 priors). Callers may
gate refusal on |
span |
tuple[int, int]
|
(start, end) character offsets in the draft. |
grounded_sources |
list[str]
|
Sources consulted during cross-reference. A finding is only emitted when none of these grounded the identifier. |
to_event_payload ¶
Return a JSON-serialisable payload for telemetry events.
Source code in src/symfonic/agent/middleware/fabrication.py
detect_fabrication ¶
detect_fabrication(
response_text: str,
tool_calls_this_turn: list[dict[str, Any]]
| None = None,
*,
hydrated_context: str = "",
user_message: str = "",
identifier_keys: list[str] | None = None,
intent_verdict: IntentVerdict | None = None,
) -> list[FabricationFinding]
Scan response_text for unresolved identifiers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_text
|
str
|
The LLM draft to scrutinise. |
required |
tool_calls_this_turn
|
list[dict[str, Any]] | None
|
Serialised tool-call records; each dict
is expected to expose a |
None
|
hydrated_context
|
str
|
The assembled memory context string used in the system prompt this turn. |
''
|
user_message
|
str
|
The user's current-turn query. |
''
|
identifier_keys
|
list[str] | None
|
Domain-configured extra key lexicon. Empty list preserves behaviour — callers can opt in per-domain. |
None
|
intent_verdict
|
IntentVerdict | None
|
v7.0.6 — the IntentClassifier verdict for the
user query this turn (the same verdict consumed by the
hydration-side intent filter and by tool routing). When
|
None
|
Returns:
| Type | Description |
|---|---|
list[FabricationFinding]
|
List of |
list[FabricationFinding]
|
Empty list for empty drafts. Never raises. |
Source code in src/symfonic/agent/middleware/fabrication.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |