_parse_google_docstring() — langchain Function Reference
Architecture documentation for the _parse_google_docstring() function in function_calling.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 46bc2e47_6090_0fe7_0261_80993c538dbc["_parse_google_docstring()"] 14ab3d97_532b_bb37_6d2f_7248501f1cb8["function_calling.py"] 46bc2e47_6090_0fe7_0261_80993c538dbc -->|defined in| 14ab3d97_532b_bb37_6d2f_7248501f1cb8 2a5add10_8549_64cb_bed6_4a2a252534e4["_convert_any_typed_dicts_to_pydantic()"] 2a5add10_8549_64cb_bed6_4a2a252534e4 -->|calls| 46bc2e47_6090_0fe7_0261_80993c538dbc style 46bc2e47_6090_0fe7_0261_80993c538dbc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/utils/function_calling.py lines 711–778
def _parse_google_docstring(
docstring: str | None,
args: list[str],
*,
error_on_invalid_docstring: bool = False,
) -> tuple[str, dict]:
"""Parse the function and argument descriptions from the docstring of a function.
Assumes the function docstring follows Google Python style guide.
Args:
docstring: The docstring to parse.
args: The list of argument names to extract descriptions for.
error_on_invalid_docstring: Whether to raise an error if the docstring is
invalid.
Returns:
A tuple of the function description and a dictionary of argument descriptions.
"""
if docstring:
docstring_blocks = docstring.split("\n\n")
if error_on_invalid_docstring:
filtered_annotations = {
arg
for arg in args
if arg not in {"run_manager", "callbacks", "runtime", "return"}
}
if filtered_annotations and (
len(docstring_blocks) < _MIN_DOCSTRING_BLOCKS
or not any(block.startswith("Args:") for block in docstring_blocks[1:])
):
msg = "Found invalid Google-Style docstring."
raise ValueError(msg)
descriptors = []
args_block = None
past_descriptors = False
for block in docstring_blocks:
if block.startswith("Args:"):
args_block = block
break
if block.startswith(("Returns:", "Example:")):
# Don't break in case Args come after
past_descriptors = True
elif not past_descriptors:
descriptors.append(block)
else:
continue
description = " ".join(descriptors).strip()
else:
if error_on_invalid_docstring:
msg = "Found invalid Google-Style docstring."
raise ValueError(msg)
description = ""
args_block = None
arg_descriptions = {}
if args_block:
arg = None
for line in args_block.split("\n")[1:]:
if ":" in line:
arg, desc = line.split(":", maxsplit=1)
arg = arg.strip()
arg_name, _, annotations_ = arg.partition(" ")
if annotations_.startswith("(") and annotations_.endswith(")"):
arg = arg_name
arg_descriptions[arg] = desc.strip()
elif arg:
arg_descriptions[arg] += " " + line.strip()
return description, arg_descriptions
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _parse_google_docstring() do?
_parse_google_docstring() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/function_calling.py.
Where is _parse_google_docstring() defined?
_parse_google_docstring() is defined in libs/core/langchain_core/utils/function_calling.py at line 711.
What calls _parse_google_docstring()?
_parse_google_docstring() is called by 1 function(s): _convert_any_typed_dicts_to_pydantic.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free