How to use prompting alone (no tool calling) to do extraction
Tool calling features are not required for generating structured output from LLMs. LLMs that are able to follow prompt instructions well can be tasked with outputting information in a given format.
This approach relies on designing good prompts and then parsing the output of the LLMs to make them extract information well.
To extract data without tool-calling features:
- Instruct the LLM to generate text following an expected format (e.g., JSON with a certain schema);
- Use output parsers to structure the model response into a desired Python object.
First we select a LLM:
Select chat model:
pip install -qU langchain-groq
import getpass
import os
if not os.environ.get("GROQ_API_KEY"):
os.environ["GROQ_API_KEY"] = getpass.getpass("Enter API key for Groq: ")
from langchain.chat_models import init_chat_model
model = init_chat_model("llama3-8b-8192", *, model_provider="groq")
tip
This tutorial is meant to be simple, but generally should really include reference examples to squeeze out performance!