LangSmithProjectNotFoundError
langsmith.errors.LangSmithProjectNotFoundError
Stack trace
langsmith.errors.LangSmithProjectNotFoundError: Project with ID 'abc123' not found or inaccessible. at langsmith.client.Client.get_project(Client.py:45) at user_code.py:12
Why it happens
This error occurs because the LangSmith client attempts to access a project ID that either does not exist, was deleted, or the API key used lacks permission to access it. It can also happen if the project ID is mistyped or missing from environment variables.
Detection
Catch LangSmithProjectNotFoundError exceptions when calling project-related methods and log the project ID and API key context to detect missing or unauthorized projects before crashing.
Causes & fixes
Incorrect or missing project ID in environment variables or code
Verify and set the correct LANGSMITH_PROJECT_ID environment variable or pass the correct project ID explicitly to the client.
API key lacks permission to access the specified project
Ensure the API key used has the necessary permissions for the project or use an API key associated with the correct account.
The project was deleted or never created in LangSmith
Create the project in the LangSmith dashboard or use an existing valid project ID.
Code: broken vs fixed
import os
from langsmith import Client
client = Client(api_key=os.environ.get('LANGSMITH_API_KEY'))
project = client.get_project(os.environ.get('LANGSMITH_PROJECT_ID')) # Raises LangSmithProjectNotFoundError
print(project) import os
from langsmith import Client
# Ensure environment variables are set correctly
client = Client(api_key=os.environ.get('LANGSMITH_API_KEY'))
project_id = os.environ.get('LANGSMITH_PROJECT_ID')
if not project_id:
raise ValueError('LANGSMITH_PROJECT_ID environment variable is not set')
project = client.get_project(project_id) # Fixed: valid project ID
print(project) Workaround
Wrap the get_project call in try/except LangSmithProjectNotFoundError, then prompt the user to verify the project ID or fallback to a default project if available.
Prevention
Use environment validation on startup to confirm the project ID exists and the API key has access, and implement monitoring to alert on 404 project errors before runtime failures.