LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
  • RemoteGraph
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDKRemoteGraph
Language
Theme
PythonlangsmithclientClientcreate_examples
Method●Since v0.0

create_examples

Create examples in a dataset.

Copy
create_examples(
  self,
  *,
  dataset_name: Optional[str] = None,
  dataset_id: Optional[ID_TYPE] = None,
  examples: Optional[Sequence[ls_schemas.ExampleCreate | dict]] = None,
  dangerously_allow_filesystem: bool = False,
  max_concurrency: Annotated[int, Field(ge=1, le=3)] = 1,
  **kwargs: Any = {}
) -> ls_schemas.UpsertExamplesResponse | dict[str, Any]

Updated to take argument 'examples', a single list where each element is the full example to create. This should be used instead of the legacy 'inputs', 'outputs', etc. arguments which split each examples attributes across arguments.

Updated to support creating examples with attachments.

Example:

from langsmith import Client

client = Client()

dataset = client.create_dataset("agent-qa")

examples = [
    {
        "inputs": {"question": "what's an agent"},
        "outputs": {"answer": "an agent is..."},
        "metadata": {"difficulty": "easy"},
    },
    {
        "inputs": {
            "question": "can you explain the agent architecture in this diagram?"
        },
        "outputs": {"answer": "this diagram shows..."},
        "attachments": {"diagram": {"mime_type": "image/png", "data": b"..."}},
        "metadata": {"difficulty": "medium"},
    },
    # more examples...
]

response = client.create_examples(dataset_name="agent-qa", examples=examples)
# -> {"example_ids": [...

Parameters

NameTypeDescription
dataset_namestr | None
Default:None

The name of the dataset to create the examples in. Must specify exactly one of dataset_name or dataset_id.

dataset_idUUID | str | None
Default:None

The ID of the dataset to create the examples in. Must specify exactly one of dataset_name or dataset_id

examplesSequence[ExampleCreate | dict]
Default:None

The examples to create.

dangerously_allow_filesystembool
Default:False

Whether to allow uploading files from the filesystem.

**kwargsAny
Default:{}

Legacy keyword args. Should not be specified if 'examples' is specified.

  • inputs (Sequence[Mapping[str, Any]]): The input values for the examples.
  • outputs (Optional[Sequence[Optional[Mapping[str, Any]]]]): The output values for the examples.
  • metadata (Optional[Sequence[Optional[Mapping[str, Any]]]]): The metadata for the examples.
  • splits (Optional[Sequence[Optional[str | List[str]]]]): The splits for the examples, which are divisions of your dataset such as 'train', 'test', or 'validation'.
  • source_run_ids (Optional[Sequence[Optional[Union[UUID, str]]]]): The IDs of the source runs associated with the examples.
  • ids (Optional[Sequence[Union[UUID, str]]]): The IDs of the examples.
View source on GitHub