sanitize_for_postgres#
- langchain_core.utils.strings.sanitize_for_postgres(
- text: str,
- replacement: str = '',
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.
- Parameters:
text (str) – The text to sanitize.
replacement (str) – String to replace NUL bytes with. Defaults to empty string.
- Returns:
The sanitized text with NUL bytes removed or replaced.
- Return type:
str
Example
>>> sanitize_for_postgres("Hello\\x00world") 'Helloworld' >>> sanitize_for_postgres("Hello\\x00world", " ") 'Hello world'