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

# Python: Sessions

> RAILSession - track RAIL scores across a multi-turn conversation.

<Info>
  **Concept:** [Policy Engine](/concepts/policy-engine) | **API:** [Evaluation API](/api-reference/evaluation)
</Info>

`RAILSession` tracks every turn of a conversation, computes aggregate statistics, and can enforce session-level policies that fire when overall quality drifts, not just on individual turns.

The turn and session policies below are the local, in-code option. Policy can also be configured per-[application](/concepts/applications) in the dashboard and enforced server-side.

<CodeGroup>
  ```python Basic session theme={null}
  from rail_score_sdk import RailScoreClient, RAILSession

  client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")
  session = RAILSession(client=client)

  for response in conversation_responses:
      outcome = session.record(content=response, mode="basic")
      print(f"Turn score: {outcome.score}")
      print(f"Session avg: {session.average_score}")

  print(f"Session summary: {session.summary}")
  ```

  ```python With turn + session policies theme={null}
  from rail_score_sdk import RailScoreClient, RAILSession, Policy, Rule

  client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")

  turn_policy = Policy(rules=[
      Rule(dimension="safety", threshold=5.0, action="block"),
  ])

  session_policy = Policy(rules=[
      Rule(dimension="safety", threshold=7.0, action="flag", aggregate="avg"),
  ])

  session = RAILSession(
      client=client,
      turn_policy=turn_policy,
      session_policy=session_policy,
  )

  for user_message in conversation:
      response = await llm(user_message)
      outcome = session.record(content=response, mode="basic")

      if outcome.turn_blocked:
          send_fallback()
      elif outcome.session_flagged:
          notify_reviewer(session.session_id)
      else:
          send(response)
  ```
</CodeGroup>

## Session properties

| Property                | Type    | Description                         |
| ----------------------- | ------- | ----------------------------------- |
| `session.session_id`    | `str`   | Unique session identifier           |
| `session.turn_count`    | `int`   | Number of turns recorded            |
| `session.average_score` | `float` | Average RAIL score across all turns |
| `session.min_score`     | `float` | Lowest turn score in the session    |
| `session.summary`       | `dict`  | Per-dimension aggregate stats       |
