# `LangChain.Utils.ChainResult`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.11/lib/utils/chain_result.ex#L1)

Module to help when working with the results of a chain.

# `to_map`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.11/lib/utils/chain_result.ex#L76)

```elixir
@spec to_map(LangChain.Chains.LLMChain.t(), map(), any()) ::
  {:ok, map()}
  | {:error, LangChain.Chains.LLMChain.t(), LangChain.LangChainError.t()}
```

Write the result to the given map as the value of the given key.

# `to_map!`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.11/lib/utils/chain_result.ex#L91)

```elixir
@spec to_map!(LangChain.Chains.LLMChain.t(), map(), any()) :: map() | no_return()
```

Write the result to the given map as the value of the given key. If invalid,
an exception is raised.

# `to_string`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.11/lib/utils/chain_result.ex#L27)

```elixir
@spec to_string(
  LangChain.Chains.LLMChain.t()
  | {:ok, LangChain.Chains.LLMChain.t()}
  | {:error, LangChain.Chains.LLMChain.t(), LangChain.LangChainError.t()}
) ::
  {:ok, String.t()}
  | {:error, LangChain.Chains.LLMChain.t(), LangChain.LangChainError.t()}
```

Return the result of the chain as a string. Returned in an `:ok` tuple format.
An `{:error, reason}` is returned for various reasons. These include:
- The last message of the chain is not an `:assistant` message.
- The last message of the chain is incomplete.
- There is no last message.

This supports passing in the final, updated LLMChain, or the result of the
`LLMChain.run/2` function.

# `to_string!`
[🔗](https://github.com/brainlid/langchain/blob/v0.8.11/lib/utils/chain_result.ex#L64)

```elixir
@spec to_string!(
  LangChain.Chains.LLMChain.t()
  | {:ok, LangChain.Chains.LLMChain.t(), LangChain.Message.t()}
  | {:error, String.t()}
) :: String.t() | no_return()
```

Return the last message's content when it is valid to use it. Otherwise it
raises and exception with the reason why it cannot be used. See the docs for
`to_string/2` for details.

---

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