> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stardog integration

> Integrate with the Stardog tool using LangChain Python.

> [Stardog](https://www.stardog.com) is an enterprise knowledge graph platform that enables organizations to unify, query, and analyze their data.\
> This integration package provides langchain tools and runnables for interacting with Stardog Voicebox, which is a natural language answering agent providing hallucination-free insights from your enterprise data.

## Overview

The Stardog LangChain integration package provides the following tools for working with Stardog Voicebox:

* `VoiceboxAskTool` - Ask questions and get natural language answers
* `VoiceboxGenerateQueryTool` - Generate SPARQL queries from natural language
* `VoiceboxSettingsTool` - Retrieve Voicebox application settings

All tools support both synchronous and asynchronous execution modes, making them suitable for various application architectures.

For complete details, see the [GitHub repository](https://github.com/stardog-union/stardog-langchain).

## Setup

### Installation

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install langchain-stardog
```

### Prerequisites

* A [Stardog Cloud](https://cloud.stardog.com) account
* A Voicebox application configured with your data
* A Voicebox API token

### Getting your API token

1. Log in to [Stardog Cloud](https://cloud.stardog.com)
2. Click on your profile icon and select **Manage API Keys**.
3. Create a new application and generate a secret.
4. Copy the API token and keep it secure.
5. For more details, see Stardog Voicebox API access.

### Credentials

Set your API token as an environment variable:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import getpass
import os

if not os.environ.get("SD_VOICEBOX_API_TOKEN"):
    os.environ["SD_VOICEBOX_API_TOKEN"] = getpass.getpass("Enter your Voicebox API token: ")
```

Optional environment variables:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
os.environ["SD_VOICEBOX_CLIENT_ID"] = "my-app"  # Client identifier (default: VBX-LANGCHAIN)
os.environ["SD_CLOUD_ENDPOINT"] = "https://cloud.stardog.com/api"  # Custom endpoint (optional)
```

## Instantiation and examples

### VoiceboxAskTool

Ask natural language questions relevant to the knowledge graph configured with your API token, and receive hallucination-free answers.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_stardog.voicebox import VoiceboxAskTool

# Tools automatically load credentials from environment variables
ask_tool = VoiceboxAskTool()

# Ask a question
result = ask_tool.invoke({"question": "What are all flights from San Francisco to New York?"})
print(result)
# Returns: Natural language answer
```

### VoiceboxSettingsTool

Retrieve Voicebox application configuration and metadata.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_stardog.voicebox import VoiceboxSettingsTool

settings_tool = VoiceboxSettingsTool()

# Get application settings
settings = settings_tool.invoke({})
print(settings)
# Returns: Configuration details like data sources, schema info, and capabilities
```

### VoiceboxGenerateQueryTool

Generate SPARQL queries for the natural language question without executing them.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_stardog.voicebox import VoiceboxGenerateQueryTool

query_tool = VoiceboxGenerateQueryTool()

# Generate a SPARQL query
query = query_tool.invoke({"question": "Which flights are delayed by more than 30 minutes?"})
print(query)
# Returns: Generated SPARQL query without executing it
```

Refer to the [Examples](https://github.com/stardog-union/stardog-langchain?tab=readme-ov-file#examples) section for different ways to use these tools and runnables.

## Class reference

For more details, see [Class Reference](https://github.com/stardog-union/stardog-langchain?tab=readme-ov-file#class-reference)

**Available classes:**

* `VoiceboxAskTool` - Ask questions and get answers
* `VoiceboxSettingsTool` - Retrieve application settings
* `VoiceboxGenerateQueryTool` - Generate SPARQL queries
* `VoiceboxAskRunnable` - Runnable for asking natural language questions
* `VoiceboxSettingsRunnable` - Settings retrieval runnable
* `VoiceboxGenerateQueryRunnable` - Query generation runnable
* `VoiceboxClient` - Core client for Voicebox API

## Learn more

* [Stardog Voicebox Documentation](https://docs.stardog.com/voicebox)
* [Stardog Cloud](https://cloud.stardog.com)
* [GitHub Repository](https://github.com/stardog-union/stardog-langchain)
* [Stardog Community](https://community.stardog.com/)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/stardog.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
