The guidance.py module#
Summary#
Classify an error code. |
|
Return the error code of a result payload, or |
|
Add |
|
Return a tool result with error guidance added; successes are returned unchanged. |
Description#
Uniform retryable / next_action guidance on tool error results.
Leaf tools report failures as {"status": "error", "error_code", "message"}
(or {"ok": False, "error": ", or a typed error model). A host LLM
still has to guess whether to retry and what to do next. "}enrich_result()
adds:
retryable:Trueonly when the same call can succeed after waiting or after the named recovery step.next_action: one concrete recovery step, when the error class has one.
Values a tool already set are never overwritten, and successful results are returned unchanged. Error codes are classified by ordered name patterns, so new codes that follow the existing naming are covered automatically.
Module detail#
- guidance.error_guidance(error_code: str, message: str = '') tuple[bool, str | None]#
Classify an error code.
- guidance.error_code_of(payload: Any) str | None#
Return the error code of a result payload, or
Nonefor a success.
- guidance.enrich_error_payload(payload: dict[str, Any]) bool#
Add
retryableandnext_actionto an error payload in place.A payload carrying
input_request(a missing user decision with anargumentname and optionaloptions) is told to ask the user and call again.
- guidance.enrich_result(result: Any, *, trace_id: str | None = None) Any#
Return a tool result with error guidance added; successes are returned unchanged.
Mappings are copied before they are changed. Pydantic error models (for example
TypedError) are converted to a mapping so the guidance fields can be added.