-
Notifications
You must be signed in to change notification settings - Fork 694
chore: add docs on custom output rendering #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5cc4445
chore: add docs on custom output rendering
ayoung19 3a3fdcc
Update src/langsmith/custom-output-rendering.mdx
ayoung19 96d8c54
Update src/langsmith/custom-output-rendering.mdx
ayoung19 fccdc15
Update src/langsmith/custom-output-rendering.mdx
ayoung19 9f33ced
Update src/langsmith/custom-output-rendering.mdx
ayoung19 9e37de1
Update src/langsmith/custom-output-rendering.mdx
ayoung19 5b53e5a
Update src/langsmith/custom-output-rendering.mdx
ayoung19 b01f165
Update src/langsmith/custom-output-rendering.mdx
ayoung19 7907dbf
Update src/langsmith/custom-output-rendering.mdx
ayoung19 abb31da
Revert "Update src/langsmith/custom-output-rendering.mdx"
ayoung19 0c105b1
suggestions
ayoung19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| --- | ||
| title: Custom output rendering | ||
| sidebarTitle: Custom output rendering | ||
| --- | ||
|
|
||
| This page describes how to use custom output rendering to visualize outputs from [_experiments_](/langsmith/evaluation-concepts#experiment) using your own custom HTML pages. | ||
ayoung19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| You'll learn how to: | ||
|
|
||
| - **[Configure custom rendering](#configure-custom-output-rendering)** in the LangSmith UI or via the API | ||
| - **[Build a custom renderer](#build-a-custom-renderer)** to display output data | ||
| - **[Understand where custom rendering appears](#where-custom-rendering-appears)** in LangSmith | ||
ayoung19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Overview | ||
|
|
||
| By default, LangSmith displays outputs in a standard JSON format. With custom output rendering, you can replace this default view with your own HTML page that receives the output data via the postMessage API and renders it however you choose. | ||
|
|
||
| This is particularly useful for: | ||
|
|
||
| - **Domain-specific formatting**: Display medical records, legal documents, or other specialized data types in their native format | ||
| - **Custom visualizations**: Create charts, graphs, or diagrams from numeric or structured output data | ||
|
|
||
| Custom rendering is configured per-[_dataset_](/langsmith/evaluation-concepts#datasets). In the future, it will also be configurable per-annotation queue. | ||
ayoung19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ayoung19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Prerequisites | ||
|
|
||
| <Check> | ||
| - A LangSmith dataset | ||
| - A web page that can receive postMessage events (can be hosted anywhere or run locally) | ||
| - Basic knowledge of HTML/JavaScript and the postMessage API | ||
| </Check> | ||
|
|
||
| ## Configure custom output rendering | ||
|
|
||
| ### In the LangSmith UI | ||
|
|
||
| To configure custom output rendering for a dataset: | ||
|
|
||
|  | ||
|
|
||
| 1. Navigate to your dataset in the **Datasets & Experiments** page | ||
| 2. Click **⋮** (three-dot menu) in the top right corner | ||
| 3. Select **Custom Output Rendering** | ||
| 4. Toggle **Enable custom output rendering** to on | ||
ayoung19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 5. Enter the URL in the **URL** field | ||
ayoung19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 6. Click **Save** | ||
|
|
||
|  | ||
|
|
||
| ### Via the API | ||
|
|
||
| You can also configure custom rendering programmatically by updating the dataset metadata: | ||
|
|
||
| <CodeGroup> | ||
| ```python Python | ||
| from langsmith import Client | ||
|
|
||
| client = Client() | ||
|
|
||
| # Update dataset metadata with iframe config | ||
| client.update_dataset( | ||
| dataset_id="your-dataset-id", | ||
| metadata={ | ||
| "iframe_config": { | ||
| "enabled": True, | ||
| "url": "https://your-domain.com/output-renderer.html" | ||
| } | ||
| } | ||
| ) | ||
| ``` | ||
|
|
||
| ```typescript TypeScript | ||
| import { Client } from "langsmith"; | ||
|
|
||
| const client = new Client(); | ||
|
|
||
| // Update dataset metadata with iframe config | ||
| await client.updateDataset("your-dataset-id", { | ||
| metadata: { | ||
| iframe_config: { | ||
| enabled: true, | ||
| url: "https://your-domain.com/output-renderer.html" | ||
| } | ||
| } | ||
| }); | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| ## Build a custom renderer | ||
|
|
||
| ### Understand the message format | ||
|
|
||
| Your HTML page will receive output data via the [postMessage API](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage). LangSmith sends messages with the following structure: | ||
|
|
||
| ```typescript | ||
| { | ||
| type: "output" | "reference", | ||
| data: { | ||
| // The outputs (actual output or reference output) | ||
| // Structure varies based on your application | ||
| }, | ||
| metadata: { | ||
| inputs: { | ||
| // The inputs that generated this output | ||
| // Structure varies based on your application | ||
| } | ||
| } | ||
| } | ||
ayoung19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| - `type`: Indicates whether this is an actual output (`"output"`) or a reference output (`"reference"`) | ||
| - `data`: The output data itself | ||
| - `metadata.inputs`: The input data that generated this output, provided for context | ||
|
|
||
| <Note> | ||
| **Message delivery timing**: LangSmith uses an exponential backoff retry mechanism to ensure your page receives the data even if it loads slowly. Messages are sent up to 6 times with increasing delays (100ms, 200ms, 400ms, 800ms, 1600ms, 3200ms). | ||
| </Note> | ||
|
|
||
| ### Example implementation | ||
|
|
||
| Here's a minimal example that displays all received messages: | ||
|
||
|
|
||
| ```html | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <title>PostMessage Echo</title> | ||
| <link rel="stylesheet" href="https://unpkg.com/sakura.css/css/sakura.css" /> | ||
| </head> | ||
| <body> | ||
| <h1>PostMessage Messages</h1> | ||
| <div id="messages"></div> | ||
| <script> | ||
| let count = 0; | ||
| window.addEventListener("message", (event) => { | ||
| count++; | ||
| const header = document.createElement("h3"); | ||
| header.appendChild(document.createTextNode(`Message ${count}`)); | ||
| const code = document.createElement("code"); | ||
| code.appendChild( | ||
| document.createTextNode(JSON.stringify(event.data, null, 2)) | ||
| ); | ||
| const pre = document.createElement("pre"); | ||
| pre.appendChild(code); | ||
| document.getElementById("messages").appendChild(header); | ||
| document.getElementById("messages").appendChild(pre); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> | ||
| ``` | ||
|
|
||
| ## Where custom rendering appears | ||
|
|
||
| When enabled, your custom rendering will replace the default output view in: | ||
|
|
||
| - **Experiment comparison view**: When comparing outputs across multiple experiments | ||
ayoung19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
|
|
||
| - **Run detail panes**: When viewing runs that are associated with a dataset | ||
ayoung19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
|
|
||
| - **Annotation queues**: When experiments are added to annotation queues for review | ||
ayoung19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|  | ||
|
|
||
| Custom rendering only applies when viewing in "pretty" mode. Users can still toggle to "raw" mode to see the original JSON. | ||
ayoung19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+633 KB
src/langsmith/images/custom-output-rendering-experiment-comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.