Home / Function/ _custom_parser() — langchain Function Reference

_custom_parser() — langchain Function Reference

Architecture documentation for the _custom_parser() function in json.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  f4a1a21e_8139_ba95_7fed_27593c884279["_custom_parser()"]
  20a5fe84_8249_f1df_53f0_7f22870f123f["json.py"]
  f4a1a21e_8139_ba95_7fed_27593c884279 -->|defined in| 20a5fe84_8249_f1df_53f0_7f22870f123f
  f4a1a21e_8139_ba95_7fed_27593c884279["_custom_parser()"]
  f4a1a21e_8139_ba95_7fed_27593c884279 -->|calls| f4a1a21e_8139_ba95_7fed_27593c884279
  9e969ef0_5395_65ea_99a0_e06563a3e201["_parse_json()"]
  9e969ef0_5395_65ea_99a0_e06563a3e201 -->|calls| f4a1a21e_8139_ba95_7fed_27593c884279
  f4a1a21e_8139_ba95_7fed_27593c884279["_custom_parser()"]
  f4a1a21e_8139_ba95_7fed_27593c884279 -->|calls| f4a1a21e_8139_ba95_7fed_27593c884279
  style f4a1a21e_8139_ba95_7fed_27593c884279 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/utils/json.py lines 33–51

def _custom_parser(multiline_string: str | bytes | bytearray) -> str:
    r"""Custom parser for multiline strings.

    The LLM response for `action_input` may be a multiline string containing unescaped
    newlines, tabs or quotes. This function replaces those characters with their escaped
    counterparts. (newlines in JSON must be double-escaped: `\\n`).

    Returns:
        The modified string with escaped newlines, tabs and quotes.
    """
    if isinstance(multiline_string, (bytes, bytearray)):
        multiline_string = multiline_string.decode()

    return re.sub(
        r'("action_input"\:\s*")(.*?)(")',
        _replace_new_line,
        multiline_string,
        flags=re.DOTALL,
    )

Domain

Subdomains

Frequently Asked Questions

What does _custom_parser() do?
_custom_parser() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/json.py.
Where is _custom_parser() defined?
_custom_parser() is defined in libs/core/langchain_core/utils/json.py at line 33.
What does _custom_parser() call?
_custom_parser() calls 1 function(s): _custom_parser.
What calls _custom_parser()?
_custom_parser() is called by 2 function(s): _custom_parser, _parse_json.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free