201-03 — Use operators

Confidence combining fallback_chain, until_ok, and try_catch around functions returning Result—zero LLM calls.

Updated

What you will build

Confidence combining fallback_chain, until_ok, and try_catch around functions returning Resultzero LLM calls.

Prerequisites

Files you will touch

Run maintained examples under examples/operators/.

Step 1 — fallback_chain recipe

PYTHONPATH=src python3 examples/operators/fallback_chain_recipe.py

Expected: prints Ok({'picked': 'second'}) (first branch Err, second Ok).

Step 2 — until_ok toy loop

PYTHONPATH=src python3 - <<'PY'
from forge_lcdl.operators import until_ok
from forge_lcdl.result import Err, Ok

def attempt(i: int):
    return Ok({"n": i}) if i >= 2 else Err("retry")

val, ok = until_ok(attempt, lambda r: isinstance(r, Ok), max_iterations=5)
print(val, ok)
PY

Expected: ({'n': 2}, True) style tuple when predicate sees Ok.

Step 3 — try_catch around risky determinism

Wrap parsing or IO that might raise; return Err objects instead of bubbling exceptions when composing pipelines.

Expected output

  • fallback_chain_recipe.py prints Ok({'picked': 'second'}) after failing the first branch.
  • The until_ok snippet prints ({'n': 2}, True) once the predicate observes Ok.
  • You can articulate how try_catch keeps Result pipelines uniform.

Common failures

Bug Symptom
Mixing Result with bare exceptions Prefer try_catch at boundaries

Verify

pytest -q tests/docs tests/examples -q

Includes operator/example smoke coverage.

What changed

Orchestration stays synchronous and typed—operators mirror functional Result style used by tasks.

Next step

201-04 — RAG and evidence.