Skip to content

core: fix _parse_google_docstring mishandling continuation lines with colons#35680

Open
Alvin Tang (alvinttang) wants to merge 1 commit intolangchain-ai:masterfrom
alvinttang:fix/parse-docstring-continuation-colon-v2
Open

core: fix _parse_google_docstring mishandling continuation lines with colons#35680
Alvin Tang (alvinttang) wants to merge 1 commit intolangchain-ai:masterfrom
alvinttang:fix/parse-docstring-continuation-colon-v2

Conversation

@alvinttang
Copy link

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.

@github-actions github-actions bot added core `langchain-core` package issues & PRs external labels Mar 9, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 9, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 13 untouched benchmarks
⏩ 23 skipped benchmarks1


Comparing alvinttang:fix/parse-docstring-continuation-colon-v2 (44843a7) with master (f838c78)

Open in CodSpeed

Footnotes

  1. 23 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@org-membership-reviewer org-membership-reviewer bot added the size: S 50-199 LOC label Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs external size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: _parse_google_docstring mishandles continuation lines containing colons

2 participants