Skip to content

Commit d3a3207

Browse files
committed
Fix another common llm error
1 parent 2fd32dd commit d3a3207

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

domain/sanitizers/terraform.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,27 @@ def fix_single_line_retention_policy(config):
103103
return config
104104

105105

106+
def fix_single_line_tentacle_retention_policy(config):
107+
"""
108+
The LLM kept insisting on using a single line tentacle_retention_policy block. This is not valid HCL2 syntax.
109+
"""
110+
111+
match = re.match(
112+
r"tentacle_retention_policy\s*{\s*quantity_to_keep\s*=\s*(\d+)\s*unit\s*=\s*\"([^\"]+)\"\s*}",
113+
config,
114+
)
115+
if match:
116+
# If we get a single line lifecycle block, just replace it with a multi-line one
117+
return (
118+
"tentacle_retention_policy {\n"
119+
f" quantity_to_keep = {match.group(1)}\n"
120+
f' unit = "{match.group(2)}"\n'
121+
"}"
122+
)
123+
124+
return config
125+
126+
106127
def fix_account_type(config):
107128
"""
108129
Fix up invalid account_type values.

domain/tools/githubactions/projects/create_template_project.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
fix_account_type,
2323
fix_single_line_retention_policy,
2424
remove_duplicate_definitions,
25+
fix_single_line_tentacle_retention_policy,
2526
)
2627
from domain.sanitizers.markdown_remove import remove_markdown_code_block
2728
from domain.tools.debug import get_params_message
@@ -279,6 +280,9 @@ async def inner_function():
279280
# Deal with the LLM returning a single line for a release_retention_policy block
280281
configuration = fix_single_line_retention_policy(configuration)
281282

283+
# Deal with the LLM returning a single line for a tentacle_retention_policy block
284+
configuration = fix_single_line_tentacle_retention_policy(configuration)
285+
282286
# Deal with invalid account_types in data blocks
283287
configuration = fix_account_type(configuration)
284288

0 commit comments

Comments
 (0)