Skip to content

Instantly share code, notes, and snippets.

@bossjones
Created August 11, 2025 13:55
Show Gist options
  • Save bossjones/e070bd12fc43328e35726ae9d7064a61 to your computer and use it in GitHub Desktop.
Save bossjones/e070bd12fc43328e35726ae9d7064a61 to your computer and use it in GitHub Desktop.
example excluding_headers_langsmith_langgraph.md

Based on the chat context, this is about excluding sensitive headers (like authentication tokens) from logs and tracing in LangGraph/LangSmith while still allowing the runtime to access them.

Here's the finalized code snippet for excluding headers from LangSmith tracing:

import langsmith as ls

__version__ = "0.1.3"

# Define headers to exclude from tracing (e.g., sensitive tokens)
_EXCLUDED_METADATA = {"x-user-token", "Authorization"}

def exclude_metadata(meta):
    """Exclude sensitive headers from metadata while adding app version"""
    return {k: v for k, v in meta.items() if k not in _EXCLUDED_METADATA} | {"my_app_version": __version__}

def hide_io(inputs):
    """Optional: Hide sensitive input/output data"""
    return {k: v for k, v in inputs.items() if k != "sensitive_field"}

# Configure LangSmith client with metadata exclusion
client = ls.Client(
    hide_inputs=hide_io,      # Optional: hide sensitive inputs
    hide_outputs=hide_io,     # Optional: hide sensitive outputs  
    hide_metadata=exclude_metadata  # Hide sensitive headers from tracing
)

# Apply the configuration globally
ls.configure(client=client)

# Your graph compilation continues normally
# graph = your_graph.compile()

Key points:

  • This solution excludes sensitive headers from LangSmith tracing on the server side
  • Headers are still accessible to the runtime/application logic
  • The _EXCLUDED_METADATA set contains header names to exclude (like "x-user-token" and "Authorization")
  • This prevents token leakage to LangSmith while maintaining functionality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment