Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:AIScientists Dev WorldSeed DM Retry With Error Feedback

From Leeroopedia
Knowledge Sources
Domains LLMs, Error_Handling
Last Updated 2026-10-26 19:00 GMT

Overview

Retry DM LLM calls with the validation error fed back into the prompt context so the model can self-correct its structured output on the next attempt.

Description

When a DM (Dungeon Master) LLM returns effects that fail Pydantic or business-rule validation, the engine does not simply retry blindly. Instead, it writes the validation error reason into `dm_ctx.error_feedback` and retries. The next LLM call includes the error message in its context, allowing the model to understand why its previous output was rejected and produce a corrected response.

This works at two layers:

  • Instructor layer: Instructor's `Mode.TOOLS` automatically sends Pydantic validation errors back to the LLM and retries (up to `max_retries`).
  • Engine layer: The `resolve_dm` loop runs up to `max_attempts=2` attempts. On validation failure, `dm_ctx.error_feedback = reason` is set before the next attempt.

Usage

Use this pattern whenever you wrap LLM calls that must return structured, validated output. It is especially critical when the LLM must produce effects that reference real entity IDs, stay within operator allow-lists, or respect max-effect limits.

The Insight (Rule of Thumb)

  • Action: On DM validation failure, set `error_feedback` on the DM context and retry up to `max_attempts` times.
  • Value: `max_attempts = 2` (one retry). Instructor's internal `max_retries = 2` provides additional Pydantic-level retries.
  • Trade-off: Extra LLM calls cost tokens and latency. With 2 engine attempts × 2 Instructor retries, worst case is 4 LLM calls per DM judgment.
  • Compatibility: Works with any `DMProvider` that accepts `DMContext`. The `error_feedback` field is read by the prompt builder.

Reasoning

LLMs frequently produce structurally valid but semantically invalid output on the first try — e.g., referencing an entity that doesn't exist, using a disallowed operator, or exceeding `max_effects`. Blind retries often produce the same error because the model has no signal about what went wrong.

Feeding the error back transforms a random retry into a targeted correction. The model sees `validation: Entity 'foo' not found for 'set'` and can fix the target reference. This dramatically reduces the fallback-narrative rate (where the DM gives up and the agent gets "The outcome is unclear.").

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment