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

# Update Testset

> Update a Testset. Only the fields provided in the request body will be updated.
If a field is provided, the new content will replace the existing content.
If a field is not provided, the existing content will remain unchanged.

When updating the schema:
- If field mappings are not provided and existing mappings reference fields that no longer exist, those mappings will be automatically removed
- To preserve all existing mappings, ensure all referenced fields remain in the updated schema
- For complete control, provide both schema and fieldMapping when updating the schema



## OpenAPI

````yaml patch /testsets/{testsetId}
openapi: 3.1.0
info:
  title: Scorecard API
  description: REST API for Scorecard
  version: 1.0.0
servers:
  - url: https://api2.scorecard.io/api/v2
security:
  - ApiKeyAuth: []
paths:
  /testsets/{testsetId}:
    patch:
      summary: Update Testset
      description: >-
        Update a Testset. Only the fields provided in the request body will be
        updated.

        If a field is provided, the new content will replace the existing
        content.

        If a field is not provided, the existing content will remain unchanged.


        When updating the schema:

        - If field mappings are not provided and existing mappings reference
        fields that no longer exist, those mappings will be automatically
        removed

        - To preserve all existing mappings, ensure all referenced fields remain
        in the updated schema

        - For complete control, provide both schema and fieldMapping when
        updating the schema
      operationId: updateTestset
      parameters:
        - in: path
          name: testsetId
          description: The ID of the Testset to update.
          schema:
            type: string
            example: '246'
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: The name of the Testset.
                description:
                  type: string
                  description: The description of the Testset.
                jsonSchema:
                  type: object
                  description: The JSON schema for each Testcase in the Testset.
                  additionalProperties: true
                fieldMapping:
                  type: object
                  properties:
                    inputs:
                      type: array
                      items:
                        type: string
                      description: Fields that represent inputs to the AI system.
                    expected:
                      type: array
                      items:
                        type: string
                      description: Fields that represent expected outputs.
                    metadata:
                      type: array
                      items:
                        type: string
                      description: Fields that are not inputs or expected outputs.
                  required:
                    - inputs
                    - expected
                    - metadata
                  description: >-
                    Maps top-level keys of the Testcase schema to their roles
                    (input/expected output). Unmapped fields are treated as
                    metadata.
            examples:
              Update metadata only:
                value:
                  name: Updated Q&A Testset
                  description: Updated description for the Q&A Testset.
                summary: Update metadata only
                description: >-
                  Simple metadata update without changing schema or mappings.
                  Updates only the name and description fields while preserving
                  the existing schema and field mappings.
              Remove schema field:
                value:
                  jsonSchema:
                    type: object
                    properties:
                      question:
                        type: string
                      idealAnswer:
                        type: string
                      provenance:
                        type: string
                summary: Remove schema field
                description: >-
                  This request removes the 'geo' field that existed in the
                  original schema, but doesn't explicitly update the field
                  mappings. Scorecard will automatically remove any field
                  mappings that reference deleted fields.
              Full schema revision:
                value:
                  jsonSchema:
                    type: object
                    properties:
                      question:
                        type: string
                      idealAnswer:
                        type: string
                      provenance:
                        type: string
                  fieldMapping:
                    inputs:
                      - question
                    expected:
                      - idealAnswer
                    metadata: []
                summary: Full schema revision
                description: >-
                  Explicit update of both schema and field mappings, allowing
                  complete control over the Testset structure. This example
                  removes the 'geo' field and explicitly updates the field
                  mappings to exclude 'provenance' from metadata.
      responses:
        '200':
          description: Testset updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Testset'
              examples:
                Updated metadata only:
                  value:
                    id: '246'
                    name: Updated Q&A Testset
                    description: Updated description for the Q&A Testset.
                    jsonSchema:
                      type: object
                      properties:
                        question:
                          type: string
                        idealAnswer:
                          type: string
                        provenance:
                          type: string
                        geo:
                          type: string
                    fieldMapping:
                      inputs:
                        - question
                      expected:
                        - idealAnswer
                      metadata:
                        - provenance
                        - geo
                  summary: Updated metadata only
                  description: >-
                    Result after updating only the Testset's name and
                    description. All schema fields and mappings remain
                    unchanged.
                Auto-updated mappings:
                  value:
                    id: '246'
                    name: Long Context Q&A
                    description: Testset for long context Q&A chatbot.
                    jsonSchema:
                      type: object
                      properties:
                        question:
                          type: string
                        idealAnswer:
                          type: string
                        provenance:
                          type: string
                    fieldMapping:
                      inputs:
                        - question
                      expected:
                        - idealAnswer
                      metadata:
                        - provenance
                  summary: Auto-updated mappings
                  description: >-
                    Result after schema update with automatic field mapping
                    cleanup. The 'geo' field has been automatically removed from
                    the metadata mapping since it no longer exists in the
                    schema.
                Custom field mapping:
                  value:
                    id: '246'
                    name: Long Context Q&A
                    description: Testset for long context Q&A chatbot.
                    jsonSchema:
                      type: object
                      properties:
                        question:
                          type: string
                        idealAnswer:
                          type: string
                        provenance:
                          type: string
                    fieldMapping:
                      inputs:
                        - question
                      expected:
                        - idealAnswer
                      metadata: []
                  summary: Custom field mapping
                  description: >-
                    Result after explicit schema and field mapping update. Note
                    that 'provenance' is not included in metadata since it
                    wasn't specified in the request's field mapping.
        '401':
          $ref: '#/components/responses/UnauthenticatedError'
        '500':
          $ref: '#/components/responses/ServiceError'
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Scorecard from 'scorecard-ai';

            const client = new Scorecard({
              apiKey: 'My API Key',
            });

            const testset = await client.testsets.update('246', {
              description: 'Updated description for the Q&A Testset.',
              name: 'Updated Q&A Testset',
            });

            console.log(testset.id);
        - lang: Python
          source: |-
            from scorecard_ai import Scorecard

            client = Scorecard(
                api_key="My API Key",
            )
            testset = client.testsets.update(
                testset_id="246",
                description="Updated description for the Q&A Testset.",
                name="Updated Q&A Testset",
            )
            print(testset.id)
        - lang: cURL
          source: |-
            curl https://api2.scorecard.io/api/v2/testsets/$TESTSET_ID \
                -X PATCH \
                -H "Authorization: Bearer $SCORECARD_API_KEY"
components:
  schemas:
    Testset:
      type: object
      properties:
        id:
          type: string
          description: The ID of the Testset.
        name:
          type: string
          description: The name of the Testset.
        description:
          type: string
          description: The description of the Testset.
        jsonSchema:
          type: object
          description: The JSON schema for each Testcase in the Testset.
          additionalProperties: true
        fieldMapping:
          type: object
          properties:
            inputs:
              type: array
              items:
                type: string
              description: Fields that represent inputs to the AI system.
            expected:
              type: array
              items:
                type: string
              description: Fields that represent expected outputs.
            metadata:
              type: array
              items:
                type: string
              description: Fields that are not inputs or expected outputs.
          required:
            - inputs
            - expected
            - metadata
          description: >-
            Maps top-level keys of the Testcase schema to their roles
            (input/expected output). Unmapped fields are treated as metadata.
      required:
        - id
        - name
        - description
        - jsonSchema
        - fieldMapping
      description: >-
        A collection of Testcases that share the same schema.

        Each Testset defines the structure of its Testcases through a JSON
        schema.

        The `fieldMapping` object maps top-level keys of the Testcase schema to
        their roles (input/expected output).

        Fields not mentioned in the `fieldMapping` during creation or update are
        treated as metadata.


        ## JSON Schema validation constraints supported:


        - **Required fields** - Fields listed in the schema's `required` array
        must be present in Testcases.

        - **Type validation** - Values must match the specified type (string,
        number, boolean, null, integer, object, array).

        - **Enum validation** - Values must be one of the options specified in
        the `enum` array.

        - **Object property validation** - Properties of objects must conform to
        their defined schemas.

        - **Array item validation** - Items in arrays must conform to the
        `items` schema.

        - **Logical composition** - Values must conform to at least one schema
        in the `anyOf` array.


        Testcases that fail validation will still be stored, but will include
        `validationErrors` detailing the issues.

        Extra fields in the Testcase data that are not in the schema will be
        stored but are ignored during validation.
    ApiError:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
        details:
          type: object
          additionalProperties: true
          x-stainless-any: true
      required:
        - code
        - message
        - details
      description: An API error.
  responses:
    UnauthenticatedError:
      description: Error indicating that the request is not authenticated.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          examples:
            Authentication failure:
              value:
                code: UNAUTHORIZED
                message: Invalid or missing authentication token
                details: {}
              summary: Authentication failure
              description: >-
                Error returned when authentication credentials are invalid or
                missing.
    ServiceError:
      description: >-
        An internal service error indicating an issue with the Scorecard
        service.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          examples:
            Internal error:
              value:
                code: INTERNAL_ERROR
                message: An unexpected error occurred while processing your request.
                details: {}
              summary: Internal error
              description: Generic error when an unexpected internal issue occurs.
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: starts with ak_

````