Extract fields from LLM JSON responses

Parse and access specific fields from structured JSON responses returned by language models.

Core Operations · Notebook · Updated

Colab runs it in your browser. If it calls a model provider, it asks for that provider's API key in a cell.

How it works

You use JSON path notation to extract specific fields from API responses and store them in computed columns.

What it covers

  • Extract text content from chat completions
  • Access nested JSON fields
  • Create separate columns for different fields

What it uses

Install
terminal
pip install pixeltable openai
Environment variables it names
OPENAI_API_KEY
Pixeltable calls
openai.chat_completions()pxt.create_table()insert()add_computed_column()

A look at the code

workflow-json-extraction.ipynb
# Add computed column for API response (returns full JSON)
t.add_computed_column(
response=openai.chat_completions(
messages=[{'role': 'user', 'content': t.prompt}],
model='gpt-4o-mini',
)
)

One cell of the notebook, copied as it is. Open it in Colab for the rest.

Browse all 103