sanitize_for_postgres() — langchain Function Reference
Architecture documentation for the sanitize_for_postgres() function in strings.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6fd41932_1dd3_9b25_f436_6c0d98108641["sanitize_for_postgres()"] 7ba4a23d_cad8_05ff_f913_ec9c15a6f08f["strings.py"] 6fd41932_1dd3_9b25_f436_6c0d98108641 -->|defined in| 7ba4a23d_cad8_05ff_f913_ec9c15a6f08f style 6fd41932_1dd3_9b25_f436_6c0d98108641 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/utils/strings.py lines 49–69
def sanitize_for_postgres(text: str, replacement: str = "") -> str:
r"""Sanitize text by removing NUL bytes that are incompatible with PostgreSQL.
PostgreSQL text fields cannot contain `NUL (0x00)` bytes, which can cause
`psycopg.DataError` when inserting documents. This function removes or replaces
such characters to ensure compatibility.
Args:
text: The text to sanitize.
replacement: String to replace `NUL` bytes with.
Returns:
The sanitized text with `NUL` bytes removed or replaced.
Example:
>>> sanitize_for_postgres("Hello\\x00world")
'Helloworld'
>>> sanitize_for_postgres("Hello\\x00world", " ")
'Hello world'
"""
return text.replace("\x00", replacement)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does sanitize_for_postgres() do?
sanitize_for_postgres() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/strings.py.
Where is sanitize_for_postgres() defined?
sanitize_for_postgres() is defined in libs/core/langchain_core/utils/strings.py at line 49.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free