MCPcopy Create free account
hub / github.com/microsoft/Webwright / parse_json_output

Function parse_json_output

src/webwright/models/base.py:107–120  ·  view source on GitHub ↗
(raw: str, *, action_field: str = "bash_command")

Source from the content-addressed store, hash-verified

105
106
107def parse_json_output(raw: str, *, action_field: str = "bash_command") -> dict[str, Any]:
108 try:
109 parsed = json.loads(raw)
110 except json.JSONDecodeError as exc:
111 raise ValueError(f"Unable to parse JSON output: {exc}") from exc
112 if not isinstance(parsed, dict):
113 raise ValueError("Model output was JSON but not a JSON object.")
114 # Strict-schema responses cannot have done=true with a non-empty action;
115 # tolerate it from non-strict callers by demoting `done`.
116 action_text = str(parsed.get(action_field, "") or "").strip()
117 if action_text and bool(parsed.get("done", False)):
118 parsed = dict(parsed)
119 parsed["done"] = False
120 return parsed
121
122
123def _validate_bash_command(command: str) -> None:

Callers 1

_query_asyncMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected