POST
/
testsets
/
{testsetId}
/
testcases
import Scorecard from 'scorecard-ai';

const client = new Scorecard({
  bearerToken: process.env['SCORECARD_API_KEY'], // This is the default and can be omitted
});

async function main() {
  const testcase = await client.testcases.create('246', {
    items: [
      {
        jsonData: {
          question: 'What is the capital of France?',
          idealAnswer: 'Paris',
          provenance: 'hand_curated',
        },
      },
      {
        jsonData: {
          question: 'What is the largest planet in our solar system?',
          idealAnswer: 'Jupiter',
          provenance: 'synthetic',
        },
      },
      {
        jsonData: {
          question: 'How many planets are in our solar system?',
          idealAnswer: 8,
          provenance: 'user_feedback',
        },
        validationErrors: [{ path: '/data/idealAnswer', message: 'Expected string, received number' }],
      },
    ],
  });

  console.log(testcase.items);
}

main();
{
  "items": [
    {
      "id": "123",
      "testsetId": "246",
      "jsonData": {
        "question": "What is the capital of France?",
        "idealAnswer": "Paris",
        "provenance": "hand_curated"
      },
      "inputs": {
        "question": "What is the capital of France?"
      },
      "labels": {
        "idealAnswer": "Paris"
      }
    },
    {
      "id": "124",
      "testsetId": "246",
      "jsonData": {
        "question": "What is the largest planet in our solar system?",
        "idealAnswer": "Jupiter",
        "provenance": "synthetic"
      },
      "inputs": {
        "question": "What is the largest planet in our solar system?"
      },
      "labels": {
        "idealAnswer": "Jupiter"
      }
    },
    {
      "id": "125",
      "testsetId": "246",
      "jsonData": {
        "question": "How many planets are in our solar system?",
        "idealAnswer": 8,
        "provenance": "user_feedback"
      },
      "inputs": {
        "question": "How many planets are in our solar system?"
      },
      "labels": {
        "idealAnswer": 8
      },
      "validationErrors": [
        {
          "path": "/data/idealAnswer",
          "message": "Expected string, received number"
        }
      ]
    }
  ]
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

testsetId
string
required

The ID of the Testset to add the Testcases to.

Example:

"246"

Body

application/json
items
object[]
required

Testcases to create (max 100).

A test case in the Scorecard system. Contains JSON data that is validated against the schema defined by its Testset. The inputs and labels fields are derived from the data field based on the Testset's fieldMapping, and include all mapped fields, including those with validation errors. Testcases are stored regardless of validation results, with any validation errors included in the validationErrors field.

Response

201
application/json
Testcases created successfully
items
object[]
required

A test case in the Scorecard system. Contains JSON data that is validated against the schema defined by its Testset. The inputs and labels fields are derived from the data field based on the Testset's fieldMapping, and include all mapped fields, including those with validation errors. Testcases are stored regardless of validation results, with any validation errors included in the validationErrors field.