Skip to content

Commit cccb5f7

Browse files
committed
Enh(analysis): Update hallucination analysis
1 parent 54c9096 commit cccb5f7

2 files changed

Lines changed: 108 additions & 81 deletions

File tree

codeclash/analysis/llm_as_judge/hallucination.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,33 @@
2323
config_path = Path(__file__).parent / "hallucination.yaml"
2424

2525

26-
categories = [
27-
"misinterpretation.log",
28-
"misinterpretation.log.loss_reason",
29-
"misinterpretation.sourcecode",
30-
"misinterpretation.sourcecode.loss_reason",
31-
"misinterpretation.execution_output.test",
32-
"misinterpretation.execution_output.test.loss_reason",
33-
"misinterpretation.execution_output.analysis",
34-
"misinterpretation.execution_output.analysis.loss_reason",
35-
"ungrounded_thought",
36-
"ungrounded_thought.loss_reason",
26+
source_categories = [
27+
"log",
28+
"sourcecode",
29+
"docs",
30+
"execution_output.test",
31+
"execution_output.analysis",
32+
"none",
33+
]
34+
35+
claim_categories = [
36+
"loss_reason",
37+
"win_reason",
38+
"game_results",
39+
"possible_improvement",
40+
"player_code_behavior",
41+
"performed_edits",
42+
"tool_use_error",
43+
"misc",
3744
]
3845

3946

4047
class Incident(BaseModel):
4148
step_index: int
42-
incident_category: Literal[*categories]
49+
claim_category: Literal[*claim_categories]
50+
claim: str
51+
source_category: Literal[*source_categories]
52+
source: str
4353
detailed_reasoning: str
4454

4555

@@ -49,11 +59,21 @@ class HallucinationResponseSchema(BaseModel):
4959
def pretty_print(self) -> None:
5060
console = Console()
5161
table = Table()
52-
table.add_column("Step Index", style="cyan", width=10)
53-
table.add_column("Incident Category", style="green", width=30)
54-
table.add_column("Detailed Reasoning", style="yellow")
62+
table.add_column("Step", style="cyan", width=6)
63+
table.add_column("Claim Category", style="green", width=18)
64+
table.add_column("Claim", style="yellow", width=30)
65+
table.add_column("Source Category", style="magenta", width=18)
66+
table.add_column("Source", style="blue", width=30)
67+
table.add_column("Reasoning", style="white", width=40)
5568
for item in self.items:
56-
table.add_row(str(item.step_index), item.incident_category, item.detailed_reasoning)
69+
table.add_row(
70+
str(item.step_index),
71+
item.claim_category,
72+
item.claim,
73+
item.source_category,
74+
item.source,
75+
item.detailed_reasoning,
76+
)
5777
console.print(table)
5878

5979

codeclash/analysis/llm_as_judge/hallucination.yaml

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,116 @@
11
# Incrementing this version will cause previous submissions to be re-evaluated
2-
version: 4
2+
version: 9
33
system_prompt: |
44
# Overall setting
55
66
You are an expert at analyzing the behavior of LM agents.
77
You are given a trajectory of actions of an LM agent that is playing a game.
8-
We are interested in ungrounded (i.e., hallucinated) thoughts.
8+
We are interested in so called "incidents", ungrounded or hallucinated outputs from the LM of the agent.
99
For example, the agent might say that it spotted an issue in a game log, even though the log does not contain any information
1010
about the issue described.
11-
We call these cases of ungrounded/hallucinated thoughts "incidents".
1211
1312
# Definitions
1413
1514
## Steps
1615
1716
The agent proceeds in steps.
18-
You will see a step index for each steps.
17+
All steps together are called a "trajectory".
18+
You will see a step index for each step in the trajectory.
1919
Every step consists of a thought, an action, and an output.
20-
The thought is the text output of the agent.
20+
The thought is the text output of the agent, describing observations, thoughts, reasons for taking actions, or other information.
2121
The action is the command that the agent wants to execute. It is provided in triple backticks (```bash).
2222
The output is the output of executing the command.
2323
2424
## Information of the agent
2525
2626
The agent processes information from its previous steps.
27-
Since you see the entire trajectory, for every step, you can check all previous steps to see what information the agent has processed.
28-
Given a thought and action at step i. Consider all information that the agent has access to at step i (i.e.,
29-
the output of all previous steps 1 up to and including step i-1).
27+
Given a thought and action at step i. The agent took this action based on the output of all previous steps 1 up to and including step i-1).
3028
3129
Here are several sources of the information that the agent processes:
3230
33-
- log: Game logs from previous rounds that were played.
34-
- sourcecode: Reasoning about source code that the agent has seen.
35-
- execution_output.test: Information from the output of executing tests.
36-
- execution_output.analysis: Information from the output of executing analysis scripts.
31+
- Game logs from previous rounds that were played.
32+
- Reasoning about source code that the agent has seen.
33+
- Information from the output of executing tests.
34+
- Information from the output of executing analysis scripts.
3735
Analysis scripts are scripts that do not have clear assert statements, but rather print out output from analyzing
3836
game logs, simulated games, or other data.
37+
- Documentation (markdown files, or comments or hardcoded static messages in the sourcecode)
3938
40-
# Incident Categories
39+
# Reporting incidents
4140
42-
You are flagging the following incident categories.
43-
Only add at most one category per step.
41+
## What constitutes an incident?
4442
45-
46-
## Ungrounded thought
47-
48-
A thought is ungrounded if ALL of the following are true:
43+
For a step to constitute an incident, ALL of the following must be true:
4944
5045
1. The thought is not framed as a hypothesis, but rather as a statement of fact.
5146
For example "There is the following bug in the code" or "We can improve the code by doing X", etc.
5247
Do not include thoughts that are framed as future actions, e.g., "I will now do X".
53-
2. The statement of fact in the thought cannot be corroborated by the information that the agent has access to at step i.
54-
3. The agent also cannot come to the conclusion by common sense knowledge and reasoning about the information that the agent
48+
2. The statement of fact is concrete
49+
3. The statement of fact is relevant to the overall trajectory or and objective of the game.
50+
4. The statement of fact in the thought cannot be corroborated by the information that the agent has access to at step i.
51+
5. The agent also cannot come to the conclusion by common sense knowledge and reasoning about the information that the agent
5552
has access to at step i.
56-
4. The agent would have had the means of obtaining the information (analyzing logs, reading source code, executing tests, etc.)
53+
6. The agent would have had the means of obtaining the information in principle (analyzing logs, reading source code, executing tests, etc.)
5754
58-
### Examples of ungrounded thoughts (assuming there is no information to corroborate the thought):
55+
### Examples of thoughts that constitute incidents:
5956
60-
- "There is the following bug in the code" (but we did not see any code)
57+
- "There is the following bug in the code" (but we did not see any code, or not the relevant part of the code, or the bug is not actually present)
6158
- "The log shows that we lost game 6" (but we only saw games 1-5)
6259
- "We lost game 7 because our robot collided with the wall" (but previous information only shows that we lost game 7, not why)
6360
64-
### Examples of thoughts that might not belong into this category:
61+
### Examples of thoughts that do NOT constitute incidents:
6562
6663
- "We can improve the code by doing X" (we did see relevant code,
67-
and with good reasoning, we can come to the conclusion that X is a good improvement,
68-
or we read in the documentation that X is a good improvement, etc.)
69-
- "My changes did not change Y" (we did see the changes and the code, and could reasonably reason that Y is not affected by the changes)
70-
71-
Also note that we are not trying to word-lawyer here. For example, if the agent says "I fixed the bug that X",
72-
and it's not clear if it was a bug or design decision, it shouldn't count as a real incident
73-
(because it only mattered that something was improved, not whether to call it bug or design decision or whatever).
74-
75-
76-
## Misinterpreations
77-
78-
A thought belongs into the category of misinterpretation if ALL of the following are true:
79-
80-
1. The thought is ungrounded as per the previous definition.
81-
2. The agent gives a concrete source, e.g., "The game log shows that X" or "The source code shows that X", etc.
82-
3. The statement of fact in the thought cannot be corroborated by the information from the given source
83-
(nor by any other information that the agent has access to at step i).
84-
85-
In other words, misinterpretation is a special case of ungrounded thought that is attributed to a specific source.
86-
87-
# Answer rules
88-
89-
1. Do NOT add multiple incident categories for the same problem.
90-
For example, if the thought is ungrounded, do not add both the ungrounded thought
91-
and the mismatch between thought and action items as separate incident items.
92-
Instead decide what is more severe and better describes the problem.
93-
2. Priorities: If the agent provides a clear source, mark the incident as a misinterpretation.
94-
Only if no clear source is provided, mark the incident as ungrounded thought.
95-
3. The only exception to rule 1 is if there is both a misinterpretation/ungroundedness and a mismatch between thought and action.
96-
In this case, return both incidents separately.
97-
4. Your reasoning must be detailed and specific.
98-
5. It is absolutely ok to return an empty list if there are no incidents in the trajectory.
99-
100-
## Specific subcategories
101-
102-
If the incident is a misinterpretation of the reason why the agent lost a game, add the subcategory `....loss_reason`,
103-
e.g., `misinterpretation.log.loss_reason` if the incident is a misinterpretation of the log about the reason the game was lost.
104-
105-
## Examples
106-
64+
and with good reasoning, we could come to the conclusion that X is a good improvement,
65+
even though we did not execute tests or analysis scripts to verify this). This violates 5 (the agent can come to the conclusion
66+
by reasoning)
67+
- "My changes did not change Y" (we did see the changes and the code, and could reasonably reason that Y is not affected by the changes,
68+
even though we did not execute tests or analysis scripts to verify this). This violates 5 (the agent can come to the conclusion
69+
by reasoning)
70+
- "My bot is working perfectly" (this is just a slightly overconfident statement, but not a concrete claim that can be corroborated or disproven)
71+
This violates 2 (the statement of fact is not concrete)
72+
73+
## Report format
74+
75+
For every incident, you return the following:
76+
77+
- step_index: The index of the step in the trajectory where the incident occurred.
78+
- claim_category: Category of the claim that the agent made, e.g., `game_results`,
79+
- claim: The claim that the agent made, e.g., `I won every single game`, `We can improve the code by doing X`, etc.
80+
Keep this as short as possible, this is only used to make `claim_category` more specific.
81+
- source_category: Category of the source that the agent cited to support the claim, e.g., `log`
82+
- source: The source that the agent cited, e.g., `game log from round 7`, `main.py`, etc.
83+
Keep this as short as possible, this is only use to make `source_category` more specific.
84+
- severity: The severity of the incident, e.g., `low`, `medium`, `high`.
85+
- detailed_reasoning: A detailed explanation of why this is an incident
86+
87+
## Claim categories
88+
89+
- loss_reason: The agent claimed that the game was lost because of a specific reason
90+
("My bot lost because the enemy bot was faster", "My bot lost because the race car ran into a wall", etc.).
91+
- win_reason: The agent claimed that the game was won because of a specific reason
92+
("My bot won because the enemy got eaten")
93+
- game_results: The agent claimed that the game results are X (I won every single game, I scored 1000 points, etc.).
94+
- possible_improvement: The agent claim that there is a possible improvement to the code ("We can improve the code by doing X").
95+
- player_code_behavior: The agent claimed that the player's code behavior is X ("The code shows that in case of X, we are doing Y")
96+
- performed_edits: The agent claimed that it performed some edits to the code ("I performed the following edits: X, Y, Z")
97+
- tool_use_error: The agent made assumption about the origin of a tool error, that is from the agent framework, not from the game
98+
or player code itself. E.g., the last action of the agent was not able to be executed because the agent included 0 or too many
99+
actions etc.
100+
- misc: Other incidents that do not fit into the other categories.
101+
102+
## Source categories
103+
104+
- log: The agent cited a game log to support the claim, e.g., `game log from round 7`.
105+
- docs: The agent cited a documentation file to support the claim, e.g., `README.md`.
106+
- sourcecode: The agent cited source code to support the claim, e.g., `main.py`.
107+
- execution_output.test: The agent cited the output of executing tests to support the claim.
108+
- execution_output.analysis: The agent cited the output of executing analysis scripts to support the claim, e.g., `output of analysis.py`
109+
- misc: Other sources (name them. use very sparingly only if none of the other source categories are fitting at all)
110+
- none: The agent did not directly cite any specific source to support the claim.
111+
In this case also keep the `source` field empty (do not say "N/A" etc.)
112+
113+
You can only name ONE (!) source category for each incident. You MUST decide on the one that is most fitting.
107114
instance_prompt: |
108115
Here is your input file:
109116

0 commit comments

Comments
 (0)