docs/v3/overview-nl.mdx
The Natural Language Layer uses generative AI to transform natural language queries into production-ready code generated by LLMs.
When you use the .chat method on a dataframe, PandasAI passes to the LLM the question, the table headers, and 5-10 rows of the Dataframe.
It then instructs the LLM to generate the most relevant code, whether Python or SQL. The code is then executed locally.
There are different output formats supported by PandasAI, which can be found here.
PandasAI allows you to configure the NL Layer with the config.set() method.
Example:
import pandasai as pai
from pandasai_litellm.litellm import LiteLLM
# Initialize LiteLLM with your OpenAI model
llm = LiteLLM(model="gpt-4.1-mini", api_key="YOUR_OPENAI_API_KEY")
pai.config.set({
"llm": llm,
"save_logs": True,
"verbose": False,
"max_retries": 3
})
boolTruepandasai.log file in the root of your project.boolFalseint3