langchain - ✅(Solved) Fix core: _parse_google_docstring mishandles continuation lines containing colons [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35679Fetched 2026-04-08 00:25:12
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
cross-referenced ×2labeled ×1referenced ×1

Root Cause

The parser uses if ":" in line to detect new argument lines without considering indentation. In Google-style docstrings, continuation lines have deeper indentation than argument definition lines, but the parser doesn't distinguish between them.

Fix Action

Fixed

PR fix notes

PR #35680: core: fix _parse_google_docstring mishandling continuation lines with colons

Description (problem / solution / changelog)

Description

_parse_google_docstring incorrectly parses multi-line argument descriptions when a continuation line contains a colon. The continuation line is treated as a new argument definition instead of being appended to the current argument's description.

Example

def search(query: str, top_k: int = 5) -> str:
    """Search the knowledge base.

    Args:
        query: The search query to use
            for finding things: important ones
        top_k: Number of results to return
    """

Before (broken): The parser creates 3 args: query, for finding things, top_k After (fixed): The parser correctly creates 2 args: query (with full description including "for finding things: important ones"), top_k

Root Cause

The parser used if ":" in line to detect new argument lines without considering indentation. In Google-style docstrings, continuation lines have deeper indentation than argument definition lines.

Fix

Detect the base indentation level from the first argument line and treat any line with deeper indentation as a continuation of the current argument's description, regardless of whether it contains a colon.

Issue

Fixes #35679

Dependencies

None.

Testing

Added 4 unit tests in test_function_calling.py::TestParseGoogleDocstring:

  • test_continuation_line_with_colon — the core bug scenario
  • test_simple_args_still_work — regression check for basic args
  • test_continuation_line_without_colon — multi-line descriptions without colons
  • test_multiple_continuation_lines_with_colons — multiple continuation lines each containing colons

All tests pass locally with Python 3.12.

Changed files

  • libs/core/langchain_core/utils/function_calling.py (modified, +16/-1)
  • libs/core/tests/unit_tests/utils/test_function_calling.py (modified, +71/-0)

PR #35733: fix: _parse_google_docstring mishandles continuation lines with colons

Description (problem / solution / changelog)

Fixes #35679

The parser was treating continuation lines as new arguments when they contained a colon. Fixed by tracking base indentation and only treating lines at the base indent level as new arguments.

Changed files

  • libs/core/langchain_core/utils/function_calling.py (modified, +8/-2)

Code Example

from langchain_core.utils.function_calling import _parse_google_docstring

def search(query: str, top_k: int = 5) -> str:
    """Search the knowledge base.

    Args:
        query: The search query to use
            for finding things: important ones
        top_k: Number of results to return
    """

result = _parse_google_docstring(search.__doc__, ["query", "top_k"])
print(result)
RAW_BUFFERClick to expand / collapse

Bug Description

_parse_google_docstring in langchain_core/utils/function_calling.py incorrectly parses multi-line argument descriptions when a continuation line contains a colon. The continuation line is treated as a new argument definition instead of being appended to the current argument's description.

Reproduction

from langchain_core.utils.function_calling import _parse_google_docstring

def search(query: str, top_k: int = 5) -> str:
    """Search the knowledge base.

    Args:
        query: The search query to use
            for finding things: important ones
        top_k: Number of results to return
    """

result = _parse_google_docstring(search.__doc__, ["query", "top_k"])
print(result)

Expected: 2 args: query (description: "The search query to use for finding things: important ones"), top_k

Actual: 3 args: query, for finding things (treated as a new arg name), top_k

Root Cause

The parser uses if ":" in line to detect new argument lines without considering indentation. In Google-style docstrings, continuation lines have deeper indentation than argument definition lines, but the parser doesn't distinguish between them.

Proposed Fix

Detect the base indentation level from the first argument line and treat any line with deeper indentation as a continuation of the current argument's description, regardless of whether it contains a colon.

extent analysis

Fix: Improved Argument Description Parsing

Fix Plan

  1. Update _parse_google_docstring function in langchain_core/utils/function_calling.py to detect base indentation level.
  2. Modify argument line detection to consider indentation levels.

Updated Code:

def _parse_google_docstring(docstring, arg_names):
    # ... (rest of the function remains the same)

    # Detect base indentation level from the first argument line
    base_indent = len(docstring) - len(docstring.lstrip())

    # Initialize current argument and description
    current_arg = None
    current_desc = ""

    # Iterate over lines in the docstring
    for line in docstring.splitlines():
        # Strip leading whitespace to get indentation level
        indent = len(line) - len(line.lstrip())

        # If line has deeper indentation, treat it as continuation
        if indent > base_indent:
            # Append line to current argument's description
            current_desc += " " + line.lstrip()
        else:
            # If line starts with a colon, treat it as a new argument
            if ":" in line:
                # Extract argument name and description
                arg_name, desc = line.split(": ", 1)
                arg_name = arg_name.strip()
                desc = desc.strip()

                # Add argument to result
                result.append((arg_name, desc))

                # Update current argument and description
                current_arg = arg_name
                current_desc = desc
            else:
                # If line doesn't start with a colon, treat it as continuation
                current_desc += " " + line.lstrip()

    # Add last argument to result
    if current_arg:
        result.append((current_arg, current_desc.strip()))

    return result

Verification

  1. Run the reproduction test case again.
  2. Verify that the output is correct: 2 args: query (

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix core: _parse_google_docstring mishandles continuation lines containing colons [2 pull requests, 1 participants]