LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • Configuration
  • Types
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
  • Vitest
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsConfigurationTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentsbackendsvalidatePath
Function●Since v1.4

validatePath

Copy
validatePath(path: string | null | undefined): string
View source on GitHub

Parameters

NameTypeDescription
path*string | null | undefined

Path to validate

Example

Copy
validatePath("foo/bar")  // Returns: "/foo/bar/"
validatePath("/./foo//bar")  // Returns: "/foo/bar/"
validatePath("../etc/passwd")  // Throws: Path traversal not allowed
validatePath("C:\\Users\\file")  // Throws: Windows absolute paths not supported

Validate and normalize a directory path.

Ensures paths are safe to use by preventing directory traversal attacks and enforcing consistent formatting. All paths are normalized to use forward slashes and start with a leading slash.

This function is designed for virtual filesystem paths and rejects Windows absolute paths (e.g., C:/..., F:/...) to maintain consistency and prevent path format ambiguity.