Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Const

LangSmith

LangSmith adds monitoring and evaluation to AI SDK applications. Initialize tracing with wrapAISDK, and use traceable for custom spans around model or tool work.

How it works

LangSmith integrates with the AI SDK by wrapping AI SDK methods before they are called. The wrapped functions send tracing data to LangSmith, while traceable can add spans around broader application logic or tool calls; serverless applications must wait for pending runs to flush before shutting down.

Syntax

wrapAISDK({ generateText })

Key points

  • LangSmith provides monitoring and evaluation capabilities for production LLM applications.
  • The integration does not require adopting LangChain's open-source frameworks.
  • Setup requires both an AI SDK model provider and the LangSmith client package.
  • Tracing begins by importing and invoking wrapAISDK before the application's AI SDK calls.
  • traceable supports spans around model calls and inside tool implementations.
  • Serverless code must allow outstanding trace runs to flush before shutdown.

Common mistakes

  • Serverless handlers must wait for LangSmith runs to finish flushing before the environment exits.
  • Use the documented LangSmith client SDK version or newer; older versions are outside the guide's setup assumption.

Example: Trace an AI SDK generation with LangSmith

import { wrapAISDK } from 'langsmith/wrappers/vercel-ai-sdk';
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

const { generateText: tracedGenerateText } = wrapAISDK({ generateText });

const result = await tracedGenerateText({
  model: openai('gpt-4o-mini'),
  prompt: 'Explain observability in one sentence.',
});

console.log(result.text);

Wrap the AI SDK function before calling it so LangSmith can trace the generation.

When to use it

Monitor LLM applications

Production AI applications need visibility into model executions and outcomes.

Evaluate AI behavior without LangChain

Teams want to evaluate application behavior while using the AI SDK directly.

Trace custom operations

Custom application logic or tool execution needs separate trace spans.

Flush traces in serverless runtimes

Serverless handlers must preserve telemetry during shutdown.

Interview questions

QHow do you enable LangSmith tracing for an AI SDK application?

Install a supported LangSmith client SDK and an AI SDK model provider. Then call wrapAISDK at the start of the code and use the wrapped AI SDK methods for traced operations.

Follow-up: How can application-specific work be traced? Use traceable around AI SDK calls or inside AI SDK tool calls to create additional trace spans.

QWhat is the role of wrapAISDK?

wrapAISDK decorates AI SDK functions so their executions are recorded by LangSmith without requiring LangChain's open-source frameworks. The application continues invoking the returned wrapped methods.

Follow-up: What should a serverless function do before returning? It should wait for all LangSmith runs to flush so traces are not lost during shutdown.

QWhen would you use traceable in addition to wrapAISDK?

traceable can surround AI SDK calls or be used within AI SDK tool calls. This adds tracing for application-level operations that are not covered by the directly wrapped SDK method.

Follow-up: When is traceable especially useful? Use it to represent custom work or nested tool-related operations as separate traceable units.

  • wrapAISDK
  • traceable
  • LangSmith client SDK
  • AI SDK model provider

Source: LangSmith. Checked 2026-10-15.