Skip to content

Commit

Permalink
unit test nits
Browse files Browse the repository at this point in the history
  • Loading branch information
baskaryan committed Dec 10, 2024
1 parent c48f4be commit 8c44b53
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions docs/evaluation/how_to_guides/unit_testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ sidebar_position: 7

# How to unit test applications (Python only)

LangSmith functional tests are assertions and expectations designed to **quickly** identify obvious bugs and regressions in your AI system. Relative to evaluations, tests typically are designed to be **fast** and **cheap** to run, focusing on **specific** functionality and edge cases.
LangSmith functional tests are assertions and expectations designed to **quickly** identify obvious bugs and regressions in your AI system.
Relative to evaluations, tests typically are designed to be **fast** and **cheap** to run, focusing on **specific** functionality and edge cases with binary assertions.
We recommend using LangSmith to track any unit tests, end-to-end integration tests, or other specific assertions that touch an LLM or other non-deterministic part of your AI system.
These should run on every commit in your CI pipeline to catch regressions early.
Ideally these run on every commit in your CI pipeline to catch regressions early.

:::note
`@unit` currently requires `langsmith` python version `>=0.1.74` (named `@unit` for versions `>=0.1.42`). If you are interested in unit testing functionality in TypeScript or other languages, please let us know at [[email protected]](mailto:[email protected]).
:::info Version requirement
`@unit` requires `langsmith` Python version `>=0.1.74`.
:::

:::info TypeScript support
If you are interested in unit testing functionality in TypeScript or other languages, please upvote/comment on [this GitHub Issue](https://github.com/langchain-ai/langsmith-sdk/issues/1321).
:::

## Write a @unit

To write a LangSmith functional test, decorate your test function with `@unit`.
If you want to track the full nested trace of the system or component being tested, you can mark those functions with `@traceable`. For example:

```python
my_app/main.py
```python
# my_app/main.py
from langsmith import traceable

@traceable # Optional
Expand All @@ -30,8 +35,8 @@ def generate_sql(user_query):

Then define your test:

```python tests/test_my_app.py
tests/test_my_app.py
```python
# tests/test_my_app.py
from langsmith import unit
from my_app.main import generate_sql

Expand Down

0 comments on commit 8c44b53

Please sign in to comment.