Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ def parse_score(response: dict) -> int:
break

if raw is None:
raise gl.UserError(f"Missing 'score' key. Got keys: {list(response.keys())}")
raise gl.vm.UserError(f"Missing 'score' key. Got keys: {list(response.keys())}")

# Coerce to int — handles "3", "3.5", floats, whitespace
try:
return max(0, int(round(float(str(raw).strip()))))
except (ValueError, TypeError):
raise gl.UserError(f"Non-numeric score: {raw}")
raise gl.vm.UserError(f"Non-numeric score: {raw}")
```

### JSON Cleanup
Expand All @@ -157,7 +157,7 @@ def clean_llm_json(text: str) -> dict:
first = text.find("{")
last = text.rfind("}")
if first == -1 or last == -1:
raise gl.UserError(f"No JSON object found in response")
raise gl.vm.UserError(f"No JSON object found in response")
text = text[first:last + 1]
text = re.sub(r",(?!\s*?[\{\[\"'\w])", "", text) # Remove trailing commas
return json.loads(text)
Expand All @@ -179,7 +179,7 @@ When using LLMs inside `run_nondet_unsafe`, consider how errors affect consensus
def leader_fn():
result = gl.nondet.exec_prompt(prompt, response_format="json")
if not isinstance(result, dict):
raise gl.UserError(f"LLM returned non-dict: {type(result)}")
raise gl.vm.UserError(f"LLM returned non-dict: {type(result)}")
return result
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def validator_fn(leaders_res: gl.vm.Result) -> bool:
try:
leader_fn()
return False # Leader errored but we succeeded — disagree
except gl.UserError as e:
except gl.vm.UserError as e:
validator_msg = str(e)
# Both hit the same business logic error — agree
if validator_msg == leader_msg:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ External APIs can return error responses. Consider checking the status code:
def fetch_data():
response = gl.nondet.web.request(api_url, method='GET')
if response.status_code >= 400 and response.status_code < 500:
raise gl.UserError(f"API returned client error: {response.status_code}")
raise gl.vm.UserError(f"API returned client error: {response.status_code}")
elif response.status_code >= 500:
raise gl.UserError(f"API temporarily unavailable: {response.status_code}")
raise gl.vm.UserError(f"API temporarily unavailable: {response.status_code}")
return json.loads(response.body.decode("utf-8"))
```

Expand Down