You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PythonCodeSplitter with strip_docstrings=True emits invalid Python for docstring-only function/method/class bodies #12330
PythonCodeSplitter with strip_docstrings=True emits a syntactically invalid chunk for any function, method, or class whose body consists solely of a docstring, for example a one-line custom exception class or a stub method. The docstring is the unit's only statement, so removing it leaves the def/class header with no body at all.
Error message
SyntaxError: expected an indented block after class definition on line 2
Expected behavior
A unit whose body is only a docstring should either keep the docstring in place or otherwise remain valid Python after strip_docstrings=True. It should never come out unparsable.
To Reproduce
fromhaystackimportDocumentfromhaystack.components.preprocessorsimportPythonCodeSplittersource='''class MyError(Exception): """Custom error raised when the widget explodes."""'''splitter=PythonCodeSplitter(min_effective_lines=1, max_effective_lines=10, strip_docstrings=True)
result=splitter.run(documents=[Document(content=source)])
importastforchunkinresult["documents"]:
ast.parse(chunk.content) # raises SyntaxError
Same result for a docstring-only top-level function and a docstring-only method.
Additional context
strip_docstrings=True is documented as a RAG-oriented option to shrink stored chunk content while still letting the docstring influence retrieval via meta_fields_to_embed=["docstrings"]. With it enabled, exactly the compact/simple declarations (one-line custom exceptions, stub/abstract methods) get corrupted into unparsable text before they are embedded or indexed.
Heads up, there's already an open PR for this: #12331 (fixes strip_docstrings on a docstring-only body). Happy to stand down if you'd rather take it, otherwise no need to duplicate the work.
Activity
Harsh23Kashyap commentedon Aug 14, 2026
I'd like to work on this. I'll open a PR shortly.
AmirF194 commentedon Aug 15, 2026
Heads up, there's already an open PR for this: #12331 (fixes strip_docstrings on a docstring-only body). Happy to stand down if you'd rather take it, otherwise no need to duplicate the work.