# create_feedback

> **Method** in `langsmith`

📖 [View in docs](https://reference.langchain.com/python/langsmith/client/Client/create_feedback)

Create feedback for a run.

!!! note

    To enable feedback to be batch uploaded in the background you must
    specify `trace_id`. *We highly encourage this for latency-sensitive environments.*

## Signature

```python
create_feedback(
    self,
    run_id: Optional[ID_TYPE] = None,
    key: str = 'unnamed',
    *,
    score: Union[float, int, bool, None] = None,
    value: Union[float, int, bool, str, dict, None] = None,
    trace_id: Optional[ID_TYPE] = None,
    correction: Union[dict, None] = None,
    comment: Union[str, None] = None,
    source_info: Optional[dict[str, Any]] = None,
    feedback_source_type: Union[ls_schemas.FeedbackSourceType, str] = ls_schemas.FeedbackSourceType.API,
    source_run_id: Optional[ID_TYPE] = None,
    feedback_id: Optional[ID_TYPE] = None,
    feedback_config: Optional[ls_schemas.FeedbackConfig] = None,
    stop_after_attempt: int = 10,
    project_id: Optional[ID_TYPE] = None,
    comparative_experiment_id: Optional[ID_TYPE] = None,
    feedback_group_id: Optional[ID_TYPE] = None,
    extra: Optional[dict] = None,
    error: Optional[bool] = None,
    session_id: Optional[ID_TYPE] = None,
    start_time: Optional[datetime.datetime] = None,
    extend_trace_retention: bool = True,
    **kwargs: Any = {},
) -> ls_schemas.Feedback
```

## Description

**Example:**

```python
from langsmith import trace, traceable, Client

@traceable
def foo(x):
    return {"y": x * 2}

@traceable
def bar(y):
    return {"z": y - 1}

client = Client()

inputs = {"x": 1}
with trace(name="foobar", inputs=inputs) as root_run:
    result = foo(**inputs)
    result = bar(**result)
    root_run.outputs = result
    trace_id = root_run.id
    child_runs = root_run.child_runs

# Provide feedback for a trace (a.k.a. a root run)
client.create_feedback(
    key="user_feedback",
    score=1,
    trace_id=trace_id,
)

# Provide feedback for a child run
foo_run_id = [run for run in child_runs if run.name == "foo"][0].id
client.create_feedback(
    key="correctness",
    score=0,
    run_id=foo_run_id,
    # trace_id= is optional but recommended to enable batched and backgrounded
    # feedback ingestion.
    trace_id=trace_id,
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `key` | `str` | No |  The name of the feedback metric. (default: `'unnamed'`) |
| `score` | `Optional[Union[float, int, bool]]` | No |  The score to rate this run on the metric or aspect. (default: `None`) |
| `value` | `Optional[Union[float, int, bool, str, dict]]` | No |  The display value or non-numeric value for this feedback. (default: `None`) |
| `run_id` | `Optional[Union[UUID, str]]` | No |  The ID of the run to provide feedback for. At least one of run_id, trace_id, or project_id must be specified. (default: `None`) |
| `trace_id` | `Optional[Union[UUID, str]]` | No |  The ID of the trace (i.e. root parent run) of the run to provide feedback for (specified by run_id). If run_id and trace_id are the same, only trace_id needs to be specified. **NOTE**: trace_id is required feedback ingestion to be batched and backgrounded. (default: `None`) |
| `correction` | `Optional[dict]` | No |  The proper ground truth for this run. (default: `None`) |
| `comment` | `Optional[str]` | No |  A comment about this feedback, such as a justification for the score or chain-of-thought trajectory for an LLM judge. (default: `None`) |
| `source_info` | `Optional[Dict[str, Any]]` | No |  Information about the source of this feedback. (default: `None`) |
| `feedback_source_type` | `Union[FeedbackSourceType, str]` | No |  The type of feedback source, such as model (for model-generated feedback) or API. (default: `ls_schemas.FeedbackSourceType.API`) |
| `source_run_id` | `Optional[Union[UUID, str]]` | No |  The ID of the run that generated this feedback, if a "model" type. (default: `None`) |
| `feedback_id` | `Optional[Union[UUID, str]]` | No |  The ID of the feedback to create. If not provided, a random UUID will be generated. (default: `None`) |
| `feedback_config` | `Optional[FeedbackConfig]` | No |  The configuration specifying how to interpret feedback with this key. Examples include continuous (with min/max bounds), categorical, or freeform. (default: `None`) |
| `stop_after_attempt` | `int, default=10` | No |  The number of times to retry the request before giving up. (default: `10`) |
| `project_id` | `Optional[Union[UUID, str]]` | No |  The ID of the project (or experiment) to provide feedback on. This is used for creating summary metrics for experiments. Cannot specify run_id or trace_id if project_id is specified, and vice versa. (default: `None`) |
| `comparative_experiment_id` | `Optional[Union[UUID, str]]` | No |  If this feedback was logged as a part of a comparative experiment, this associates the feedback with that experiment. (default: `None`) |
| `feedback_group_id` | `Optional[Union[UUID, str]]` | No |  When logging preferences, ranking runs, or other comparative feedback, this is used to group feedback together. (default: `None`) |
| `extra` | `Optional[Dict]` | No |  Metadata for the feedback. (default: `None`) |
| `session_id` | `Optional[Union[UUID, str]]` | No |  The session (project) ID of the run this feedback is for. Used to optimize feedback ingestion by avoiding server-side lookups. (default: `None`) |
| `start_time` | `Optional[datetime]` | No |  The start time of the run this feedback is for. Used to optimize feedback ingestion by avoiding server-side lookups. (default: `None`) |
| `extend_trace_retention` | `bool, default=True` | No |  If false, create the feedback without extending the trace's retention tier. (default: `True`) |
| `**kwargs` | `Any` | No |  Additional keyword arguments. (default: `{}`) |

## Returns

`ls_schemas.Feedback`

The created feedback object.

---

[View source on GitHub](https://github.com/langchain-ai/langsmith-sdk/blob/d6cd6082f09e7826a2d6afe444ae6119e61b82a6/python/langsmith/client.py#L7651)