_parse_code_json() — langchain Function Reference
Architecture documentation for the _parse_code_json() function in groq.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 4a0480f6_7bf8_0fd9_4661_c2a6287501d8["_parse_code_json()"] 0e434ace_bc91_58ed_0c26_ebc25d9a766a["groq.py"] 4a0480f6_7bf8_0fd9_4661_c2a6287501d8 -->|defined in| 0e434ace_bc91_58ed_0c26_ebc25d9a766a 9d4d24e2_43fa_881e_628f_8a0a55cde2e6["_convert_to_v1_from_groq()"] 9d4d24e2_43fa_881e_628f_8a0a55cde2e6 -->|calls| 4a0480f6_7bf8_0fd9_4661_c2a6287501d8 style 4a0480f6_7bf8_0fd9_4661_c2a6287501d8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/messages/block_translators/groq.py lines 30–48
def _parse_code_json(s: str) -> dict:
"""Extract Python code from Groq built-in tool content.
Extracts the value of the 'code' field from a string of the form:
{"code": some_arbitrary_text_with_unescaped_quotes}
As Groq may not escape quotes in the executed tools, e.g.:
```
'{"code": "import math; print("The square root of 101 is: "); print(math.sqrt(101))"}'
```
""" # noqa: E501
m = re.fullmatch(r'\s*\{\s*"code"\s*:\s*"(.*)"\s*\}\s*', s, flags=re.DOTALL)
if not m:
msg = (
"Could not extract Python code from Groq tool arguments. "
"Expected a JSON object with a 'code' field."
)
raise ValueError(msg)
return {"code": m.group(1)}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _parse_code_json() do?
_parse_code_json() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/block_translators/groq.py.
Where is _parse_code_json() defined?
_parse_code_json() is defined in libs/core/langchain_core/messages/block_translators/groq.py at line 30.
What calls _parse_code_json()?
_parse_code_json() is called by 1 function(s): _convert_to_v1_from_groq.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free