Tighten LLM proposal schema

This commit is contained in:
2026-04-04 23:24:32 +08:00
parent 00778eff42
commit 8b024c72f1
4 changed files with 133 additions and 0 deletions

View File

@@ -31,7 +31,9 @@ def build_prompt(
"You are tuning an OpenAI-compatible serving engine.",
"Return exactly one JSON object with keys: observation, diagnosis, config_patch, expected_effects, why_not_previous_failures.",
"config_patch must contain env_patch and flag_patch.",
"expected_effects must be a JSON array of short strings, not an object.",
"Only use allowed tunable env keys and allowed tunable flag keys.",
"Do not wrap the JSON in markdown fences or any extra text.",
"",
"Study stack:",
json.dumps(

View File

@@ -398,6 +398,17 @@ class Proposal:
expected_effects = data.get("expected_effects")
if isinstance(expected_effects, str):
expected_effects_value = [expected_effects.strip()] if expected_effects.strip() else []
elif isinstance(expected_effects, Mapping):
expected_effects_value = []
for key, value in expected_effects.items():
key_text = str(key).strip()
value_text = str(value).strip()
if key_text and value_text:
expected_effects_value.append(f"{key_text}: {value_text}")
elif key_text:
expected_effects_value.append(key_text)
elif value_text:
expected_effects_value.append(value_text)
else:
expected_effects_value = _coerce_str_list(
expected_effects, context="proposal.expected_effects"