Documents
Home>Documents>AI>Agent>LangChain

LangChain Code Interpreter with BigQuery: A Hands-On Guide

5 min readFeb 10, 2025Feb 22, 2026

chap11 Project

chap11 is a hands-on project integrating LangChain's Code Interpreter functionality with BigQuery. It ran from February to March 2025 across 9 commits.

What Is a Code Interpreter?

A feature that lets an LLM generate and execute Python code directly:

sequenceDiagram
    participant U as 사용자
    participant A as LLM Agent
    participant I as Code Interpreter
    participant B as BigQuery

    U->>A: "매출 데이터 분석해줘"
    A->>I: Python 코드 생성
    I->>B: SQL 쿼리 실행
    B-->>I: 데이터 반환
    I->>I: pandas 분석 + 시각화
    I-->>A: 결과 + 차트
    A-->>U: 분석 결과 정리

BigQuery Integration

from google.cloud import bigquery
from langchain.agents import create_sql_agent

client = bigquery.Client(project="my-project")

# BigQuery를 LangChain SQL Agent에 연결
db = SQLDatabase.from_uri(
    "bigquery://my-project/my-dataset"
)

agent = create_sql_agent(
    llm=ChatOpenAI(model="gpt-4"),
    db=db,
    verbose=True
)

CodeInterpreterClient Updates

In chap11_updated (7 commits), CodeInterpreterClient was refactored to align with the latest API.

Responses API Integration

A version leveraging the OpenAI Responses API was also implemented on 2/25:

# Responses API → 더 간단한 코드 실행
response = client.responses.create(
    model="gpt-4-turbo",
    tools=[{"type": "code_interpreter"}],
    messages=[
        {"role": "user", "content": "BigQuery 데이터 분석해줘"}
    ]
)

Lessons Learned

  1. Code Interpreter is powerful for automating data analysis.
  2. Watch costs when integrating with BigQuery — billing is based on bytes scanned.
  3. The Responses API makes tool use simpler than the legacy Completions API.
Tags
LangChainCode InterpreterBigQuerydata analysisSQL