Repository: confident-ai/deepeval
Issue: ToolCorrectnessMetric raises ZeroDivisionError when expected_tools is empty
Root cause: Validation Gap

**Describe the bug**
The `ToolCorrectnessMetric` raises a `ZeroDivisionError` when called with an `LLMTestCase` for which `expected_tools` is empty. In my use case, I want to benchmark that the LLM only calls a tool when necessary, i.e. with an empty `expected_tools` list.

**To Reproduce**
1. Run minimal example:
```
from deepeval.metrics import ToolCorrectnessMetric
from deepeval.test_case import LLMTestCase

metric = ToolCorrectnessMetric()
test_case = LLMTestCase(
    input="What is an elephant?",
    actual_output="(...)",
    tools_called=[],
    expected_tools=[]
)

metric.measure(test_case)
print(metric.score)
```
2. See error `ZeroDivisionError: division by zero` raised by `metric.measure(test_case)`. This is caused by the line ```score = len(used_expected_tools) / len(self.expected_tools)``` in `_calculate_score()` of the `ToolCorrectnessMetric`.

**Expected behavior**
I expected a perfect score of 1 for the minimal example, which represents a test case where no tool call was executed and no tool call was expected.

**Software versions:**
 - OS: macOS 15.2 (24C101)
 - Python 3.12
 - deepeval 2.0.5

**Additional context**
This can be mitigated by using `should_exact_match=True`, but I did not find this workaround to be documented.


 Hey @j-mesnil  and @trevor-cai 👋 , can you please confirm if this issue is still open? If yes, could you assign it to me? I’d like to work on fixing it.

Hey @Stu-ops, This issue is still unresolved and I have assigned it to you for the next 48 hours. If there is no activity after that and someone else is interested in taking the issue for the hacktoberfest, then I will re-assign it. Also, if there are any specific issues you would be interested in addressing for the hacktoberfest, just let me know and I will consider adding the label.

Good luck :-)

Please include a test that proves the fix.

Hey @trevor-cai  I made pr for this issue, you can review and see the changes for it.
And also, please can you tag my pr with the “hacktoberfest-accepted” after accepting it and also share any type of suggestions regarding the pr, because it was my first pr, so I don't know so much about it.
for any type information related to the hactoberfest is given here:[Hactoberfest](https://hacktoberfest.com/participation/)

@trevor-cai (I accidentally merged it, feel free to reopen this if required)

@penguine-ip  and @trevor-cai, thanks for accepting this pr I am very happy to see that you are accepting my pr, but can you also label this PR with “hacktoberfest-accepted”? Does it count in the Haactoberfest, please! And was there any mistake in it? If yes, I can make an improvement in this. in the last, can you also assign the other issue that is #2118 (if possible).

Hi @Stu-ops  and @penguine-ip ,

Sorry for the confusion here. The divide-by-zero error I was recalling actually occurs in the `MultiTurnMCPUseMetric`, not in the `ToolCorrectnessMetric`. This issue refers to the latter, which no longer has a divide-by-zero problem.

I’ll revert the merged PR since the fix was applied to the wrong metric. My apologies for the mix-up and for any extra work this caused.

I’ve opened a new issue that correctly describes the problem I intended: https://github.com/confident-ai/deepeval/issues/2138.  

@Stu-ops, please comment on issue #2138 and I’ll assign it to you and add the necessary Hacktoberfest label so it counts toward your contributions. I can't assign it to you until you have posted a comment.


Hey @trevor-cai can you also assign me issue #2118 i want to fix it, but due to no response i don't know whether they want to give me or not? i caused the work to be suspended towards this. if possible, can you assign me as soon as possible to start working on it?

Hey @trevor-cai and @penguine-ip  i raised the pr for this can you reviewed it so that i can work get my pr count in hactoberfest as soon as possible .