# `LangChain.Chains.LLMChain.Modes.UntilSuccess`
[🔗](https://github.com/brainlid/langchain/blob/v0.15.3/lib/chains/llm_chain/modes/until_success.ex#L1)

Execution mode that loops until a successful result.

Calls the LLM, executes tool calls, and repeats until:
- The last message is an assistant response (success)
- The last message is a tool result with no errors (success)
- Max retry count is exceeded (error)
- Max runs is exceeded (error)

An assistant message that leaves the model's turn open (see
`LangChain.Message.continues_turn?/1`) is not a response, so the LLM is
called again. That is a message the provider reported as not ending the
turn, or one that is narration only: the model has said what it is about to
do without doing it.

## Options

- `:max_runs` - Maximum LLM calls in one run before returning
  `%LangChainError{type: "exceeded_max_runs"}`. Default: 25. The count starts
  at 0 on every `LLMChain.run/2`.
- `:force_recurse` — When `true`, forces recursion even after a successful
  result. Default: `false`.

## Usage

    LLMChain.run(chain, mode: :until_success)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
