# SnowflakeCortexAnalyst

> **Class** in `langchain_snowflake`

📖 [View in docs](https://reference.langchain.com/python/langchain-snowflake/tools/analyst/SnowflakeCortexAnalyst)

Snowflake Cortex Analyst integration for Text2SQL.

Cortex Analyst is Snowflake's AI-powered tool that converts natural language
questions into SQL queries and executes them against your Snowflake data.

## Signature

```python
SnowflakeCortexAnalyst(
    self,
    **kwargs = {},
)
```

## Description

**Setup:**

Install ``langchain-snowflake`` and configure Snowflake connection.

.. code-block:: bash

    pip install -U langchain-snowflake

**Key init args:**

session: Optional[Session]
    Active Snowflake session
account: str
    Snowflake account identifier
user: str
    Snowflake username
database: str
    Database to query
schema: str
    Schema to query
warehouse: Optional[str]
    Warehouse to use for queries
use_rest_api: bool
    Whether to use REST API (default: True) or SQL function fallback
semantic_model_file: Optional[str]
    Path to semantic model file on Snowflake stage

**Instantiate:**

.. code-block:: python

from . import SnowflakeCortexAnalyst

analyst = SnowflakeCortexAnalyst(
    session=session,
    semantic_model_file="@my_stage/semantic_model.yaml"
)

**Use within an agent:**

.. code-block:: python

from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from .. import ChatSnowflake

llm = ChatSnowflake(model="claude-3-5-sonnet", session=session)
tools = [analyst]

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful data analyst assistant."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)

response = agent_executor.invoke({
    "input": "What were our top 5 products by revenue last quarter?"
})

## Extends

- `BaseTool`
- `SnowflakeConnectionMixin`

## Constructors

```python
__init__(
    self,
    **kwargs = {},
)
```


## Properties

- `name`
- `description`
- `args_schema`
- `role`
- `semantic_model_file`
- `semantic_view`
- `use_rest_api`
- `enable_streaming`

---

[View source on GitHub](https://github.com/langchain-ai/langchain-snowflake/blob/fab0c716e9197e2afb7ee433491251a8ef12b9c4/libs/snowflake/langchain_snowflake/tools/analyst.py#L23)