LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coreutilsutils
    Moduleā—Since v0.1

    utils

    Generic utility functions.

    Attributes

    Functions

    View source on GitHub
    attribute
    LC_AUTO_PREFIX: str
    attribute
    LC_ID_PREFIX: str
    function
    is_pydantic_v1_subclass
    function
    xor_args
    function
    raise_for_status_with_text
    function
    mock_now
    function
    guard_import
    function
    check_package_version
    function
    get_pydantic_field_names
    function
    build_extra_kwargs
    function
    convert_to_secret_str
    function
    from_env
    function
    secret_from_env
    function
    ensure_id

    LangChain auto-generated ID prefix for messages and content blocks.

    Internal tracing/callback system identifier.

    Used for:

    • Tracing. Every LangChain operation (LLM call, chain execution, tool use, etc.) gets a unique run_id (UUID)
    • Enables tracking parent-child relationships between operations

    Check if the given class is Pydantic v1-like.

    Validate specified keyword args are mutually exclusive.

    Raise an error with the response text.

    Context manager for mocking out datetime.now() in unit tests.

    Dynamically import a module.

    Raise an exception if the module is not installed.

    Check the version of a package.

    Get field names, including aliases, for a pydantic class.

    Build extra kwargs from values and extra_kwargs.

    DON'T USE

    Kept for backwards-compatibility but should never have been public. Use the internal _build_model_kwargs function instead.

    Convert a string to a SecretStr if needed.

    Create a factory method that gets a value from an environment variable.

    Secret from env.

    Ensure the ID is a valid string, generating a new UUID if not provided.

    Auto-generated UUIDs are prefixed by 'lc_' to indicate they are LangChain-generated IDs.