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

# LlamaIndex integration

> Use QWEDQueryEngine wrapper for LlamaIndex to add verification to RAG pipelines. Includes math and fact checking for retrieval-augmented generation workflows.

## Installation

```bash theme={null}
pip install qwed llama-index
```

## Quick start

```python theme={null}
from qwed_sdk.llamaindex import QWEDQueryEngine

# Wrap any query engine with verification
verified_engine = QWEDQueryEngine(base_engine)

response = verified_engine.query("What is 15% of 200?")
print(response.verified)  # True/False
print(response.response)  # The answer
```

## QWEDQueryEngine

Wraps any LlamaIndex query engine to add verification:

```python theme={null}
from llama_index.core import VectorStoreIndex
from qwed_sdk.llamaindex import QWEDQueryEngine

# Create base engine
index = VectorStoreIndex.from_documents(documents)
base_engine = index.as_query_engine()

# Wrap with QWED
verified_engine = QWEDQueryEngine(
    base_engine,
    api_key="qwed_...",
    verify_math=True,
    verify_facts=True,
    auto_correct=False,
)

response = verified_engine.query("Calculate the total cost")
print(response.verified)
```

## How responses are verified

> [!NOTE]
>
> Changed in v8.0.0 ([GHSA-83v6-6h23-pvp4](https://github.com/QWED-AI/qwed-verification/security/advisories/GHSA-83v6-6h23-pvp4))

`response.verified` is `True` only when a QWED engine checked the response and the server admitted it. The integration reads the client's `is_verified`, which follows the server's admission. Everything else fails closed:

| Case | `verified` | `status` |
| - | - | - |
| A math response the server admits | `True` | Server status, for example `VERIFIED` |
| A math response the server does not admit | `False` | Server status, for example `BLOCKED` |
| No QWED engine applies, or a fact query without source context | `False` | `UNVERIFIABLE` |
| The check raises an error | `False` | `ERROR` |

```python theme={null}
response = verified_engine.query("Where is the Eiffel Tower?")

if not response.verified:
    # UNVERIFIABLE, ERROR, or not admitted by the server
    print(response.status)
```

> [!WARNING]
>
> Before v8.0.0, `QWEDQueryEngine` returned `verified=True` with status `PASSED` for any response no engine checked, including fact-style queries. Don't rely on `verified=True` from earlier versions.

## QWEDVerificationTransform

Node postprocessor that verifies retrieved content:

```python theme={null}
from qwed_sdk.llamaindex import QWEDVerificationTransform

engine = index.as_query_engine(
    node_postprocessors=[
        QWEDVerificationTransform(
            verify_math=True,
            verify_code=True,
        )
    ]
)
```

The transform sets `qwed_verified` in each node's metadata:

* `True` only when a check ran and the server admitted the content.
* `False` when the server refused the content or the check raised an error.
* `False` together with `qwed_checked: False` when the node had nothing to check.

## QWEDCallbackHandler

Track verification across all operations:

```python theme={null}
from llama_index.core import Settings
from qwed_sdk.llamaindex import QWEDCallbackHandler

Settings.callback_manager.add_handler(
    QWEDCallbackHandler(log_all=True)
)
```

## QWEDVerifyTool

For LlamaIndex agents:

```python theme={null}
from llama_index.core.agent import ReActAgent
from qwed_sdk.llamaindex import QWEDVerifyTool

tools = [QWEDVerifyTool()]
agent = ReActAgent.from_tools(tools, llm=llm)
```

## VerifiedResponse

```python theme={null}
@dataclass
class VerifiedResponse:
    response: str
    verified: bool
    status: str
    confidence: float
    attestation: Optional[str]
    source_nodes: List[Any]
```


## Related topics

- [QWED Open Responses guards for verified AI agents](https://docs.qwedai.tech/open-responses/guards.md)
- [Changelog](https://docs.qwedai.tech/changelog.md)
- [QWED integration guide](https://docs.qwedai.tech/advanced/integration-guide.md)
- [QWED design decisions](https://docs.qwedai.tech/advanced/design.md)
- [LangChain integration for verified AI agents](https://docs.qwedai.tech/open-responses/langchain.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.