Repository: truera/trulens
Issue: [BUG] groundedness function raises UnboundLocalError
Root cause: Validation Gap

**Bug Description**
The metrics `groundedness_measure_with_cot_reasons` and `groundedness_measure_with_cot_reasons_consider_answerability` may raise `UnboundLocalError`, as the variable `normalized_reason` is not set if no match was found.

**To Reproduce**
```python
import boto3
from trulens.providers.bedrock import Bedrock

client = boto3.client(service_name="bedrock-runtime")
bedrock = Bedrock(
    model_id="anthropic.claude-3-haiku-20240307-v1:0",
    client=client,
)

bedrock.groundedness_measure_with_cot_reasons(
    source=(
        "* A cow is a mammal.\n" "* A cow lives on a farm.\n" "* A cow has 4 stomachs."
    ),
    statement="A cow has 4 stomachs and has a diet that relies primarily on grazing.",
)
```

**Expected behavior**
no error

**Relevant Logs/Tracebacks**
Traceback (most recent call last):
  File "/home/user/projects/my_project/scripts/genai_metrics.py", line 24, in <module>
    bedrock.groundedness_measure_with_cot_reasons(
  File "/home/user/miniconda3/envs/my-env/lib/python3.12/site-packages/trulens/feedback/llm_provider.py", line 1645, in groundedness_measure_with_cot_reasons
    results.append(future.result())
                   ^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/my-env/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/my-env/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/home/user/miniconda3/envs/my-env/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/my-env/lib/python3.12/site-packages/trulens/core/utils/python.py", line 561, in _future_target_wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/miniconda3/envs/my-env/lib/python3.12/site-packages/trulens/feedback/llm_provider.py", line 1634, in evaluate_hypothesis
    return index, score, normalized_reason
                         ^^^^^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'normalized_reason' where it is not associated with a value

**Environment:**

- OS: [e.g. MacOS, Windows]: Ubuntu 22.04
- Python Version: 3.12.5
- TruLens version: 1.0.8


Thanks @drooms-sandrus - fixed this in `1.0.9` (released now). Can you give this another try?

@sfc-gh-jreini Thanks for the quick response! I've given it a try (with 1.0.9) and there's a related issue in `groundedness_measure_with_cot_reasons_consider_answerability`:

```python
bedrock.groundedness_measure_with_cot_reasons_consider_answerability(
    source=(
        "* A cow is a mammal.\n"
        "* A cow lives on a farm.\n"
        "* A cow has 4 stomachs."
    ),
    statement="A cow has 4 stomachs and has a diet that relies primarily on grazing.",
    question="How many stomachs does a cow have?",
)
```

leads to

```
Traceback (most recent call last):
  File "/home/user/projects/my_project/scripts/genai_metrics.py", line 25, in <module>
    bedrock.groundedness_measure_with_cot_reasons_consider_answerability(
  File "/home/user/miniconda3/envs/my-env/lib/python3.12/site-packages/trulens/feedback/llm_provider.py", line 1852, in groundedness_measure_with_cot_reasons_consider_answerability
    if "reason" in reason
       ^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable
```

I've released `1.0.10 patch` with better error handling for this and related processing issues that will help here.

I'd also recommend using `sonnet` instead of `haiku` for `groundedness` because `haiku` is failing to successfully complete the intermediate processing steps required.

@drooms-sandrus can you also give this another try? Thanks again!

@sfc-gh-jreini Thanks again for the quick fix :) I've tried it out and it works now.