# Exclude Template Text

> A guide on how to exclude template text from plagiarism scans using the Copyleaks API.

The **Exclude Template** feature allows you to refine the analysis of documents by excluding specific sections based on a predefined template. This is particularly useful for scenarios like checking student exams where the questions are the same for everyone, and you only want to scan the student's answers.

This guide will walk you through the process of creating a template and then using it to exclude content from your scans.

## How it works

To better understand how template exclusion works, consider the following scenario where a teacher wants to scan student exams but exclude the questions.

| The Template _(indexed beforehand)_ | Student Submission _(the file you scan)_ | What Copyleaks Scans _(the actual analysis)_ |
| :--- | :--- | :--- |
| Question 1: Explain the process of photosynthesis. | Question 1: Explain the process of photosynthesis.<br /><br />Answer: Photosynthesis is the process used by plants... | ~~Question 1: Explain the process of photosynthesis.~~<br /><br />Answer: Photosynthesis is the process used by plants... |

By excluding the template text, the plagiarism scan focuses solely on the student's original answer, preventing false positives from the question text itself.

## Template sourcing

Templates for exclusion can be referenced in two ways:
- **From a normal submitted scan:** Reference any existing `scanId` from your submissions (saved short-term which is determined by the `expiration` property).
- **From your Private Cloud Hub:** Index the template document into your [**Private Cloud Hub**](/concepts/features/data-hubs/) (for recurring or long-term use).

This approach is widely used by many institutions to ensure that commonly repeated content, such as exam questions, rubrics, or boilerplate instructions, does not affect results.

## Get started

<Steps>
  <Step>
    ### Before you begin
    Before you start, ensure you have the following:
    - An active Copyleaks account. If you don't have one, **[sign up for free](https://api.copyleaks.com/signup)**.
    - You can find your API key on the **[API Dashboard](https://api.copyleaks.com/dashboard)**.
  </Step>

  <Step>
    ### Installation
    <InstallSDKs />
  </Step>

  <Step>
    ### Login
    <GuideLogin />
  </Step>

  <Step>
    ### Create a template (index a document)

    First, you need to submit the document that contains the text you want to exclude (the template). You will "index" this document into a repository (either in your Private Cloud Hub or Shared Data Hub).

    In this example, we will submit a file with the ID `my-template-index` to a repository named `my_private_cloud_exam_template`.

    <CodeGroup>
        ```http title="HTTP" icon="globe"
        PUT https://api.copyleaks.com/v3/scans/submit/file/my-template-index
        Content-Type: application/json
        Authorization: Bearer <YOUR_AUTH_TOKEN>

        {
          "base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
          "filename": "exam_template.txt",
          "properties": {
            "action": 2,
            "indexing": {
                "repositories": [
                    {
                        "id": "6e870e0bb2264",
                        "includeMySubmissions": true,
                        "includeOthersSubmissions": true
                    }
                ],
                "copyleaksDb": false
            },
            "webhooks": {
                "status": "https://your-server.com/webhook/{STATUS}"
            }
          }
        }
        ```
        ```bash title="cURL" icon="terminal"
        curl -X PUT "https://api.copyleaks.com/v3/scans/submit/file/my-template-index" \
             -H "Authorization: Bearer <YOUR_AUTH_TOKEN>" \
             -H "Content-Type: application/json" \
             -d '{
                   "base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
                   "filename": "exam_template.txt",
                   "properties": {
                     "action": 2,
                     "indexing": {
                       "repositories": [
                         {
                           "id": "6e870e0bb2264",
                           "includeMySubmissions": true,
                           "includeOthersSubmissions": true
                         }
                       ],
                       "copyleaksDb": false
                     },
                     "webhooks": {
                       "status": "https://your-server.com/webhook/{STATUS}"
                     },
                     "sandbox": true
                   }
                 }'
        ```
        ```python title="Python" icon="python"
        import requests
        import base64

        # Template content
        template_content = "This is the exam template text."
        base64_content = base64.b64encode(template_content.encode()).decode('utf-8')

        url = "https://api.copyleaks.com/v3/scans/submit/file/my-template-index"
        payload = {
            "base64": base64_content,
            "filename": "exam_template.txt",
            "properties": {
                "action": 2,
                "indexing": {
                    "repositories": [
                        {
                            "id": "6e870e0bb2264",
                            "includeMySubmissions": True,
                            "includeOthersSubmissions": True
                        }
                    ],
                    "copyleaksDb": False
                },
                "webhooks": {
                    "status": "https://your-server.com/webhook/{STATUS}"
                },
                "sandbox": True
            }
        }
        headers = {
            "Authorization": "Bearer <YOUR_AUTH_TOKEN>",
            "Content-Type": "application/json"
        }

        response = requests.put(url, json=payload, headers=headers)
        print(response.json())
        ```
        ```javascript title="JavaScript" icon="square-js"
        const axios = require('axios');

        const url = 'https://api.copyleaks.com/v3/scans/submit/file/my-template-index';
        const headers = {
            'Authorization': 'Bearer <YOUR_AUTH_TOKEN>',
            'Content-Type': 'application/json'
        };
        
        const data = {
            base64: "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
            filename: "exam_template.txt",
            properties: {
                action: 2,
                indexing: {
                    repositories: [
                        {
                            id: "6e870e0bb2264",
                            includeMySubmissions: true,
                            includeOthersSubmissions: true
                        }
                    ],
                    copyleaksDb: false
                },
                webhooks: {
                    status: "https://your-server.com/webhook/{STATUS}"
                },
                sandbox: true
            }
        };

        axios.put(url, data, { headers })
            .then(response => console.log(response.data))
            .catch(error => console.error(error));
        ```
        ```java title="Java" icon="java"
        import classes.Copyleaks;
        import models.submissions.CopyleaksFileSubmissionModel;
        import models.submissions.properties.*;
        import java.util.Base64;
        import java.nio.charset.StandardCharsets;

        String scanId = "my-template-index";
        String base64Content = Base64.getEncoder().encodeToString("This is the exam template text.".getBytes(StandardCharsets.UTF_8));

        // Create submission properties
        SubmissionProperties properties = new SubmissionProperties(new SubmissionWebhooks("https://your-server.com/webhook/{STATUS}"));
        properties.setSandbox(true);

        // Action 2 is 'Index Only'
        properties.setAction(SubmissionActions.IndexOnly);

        // Configure indexing to Private Cloud Hub
        SubmissionIndexingRepository repo = new SubmissionIndexingRepository();
        repo.setId("6e870e0bb2264");
        SubmissionIndexing indexing = new SubmissionIndexing();
        // Requires copyleaks-java-sdk SubmissionIndexing.setRepositories (coming soon)
        indexing.setRepositories(new SubmissionIndexingRepository[]{ repo });
        properties.setIndexing(indexing);

        // Create and submit the file
        CopyleaksFileSubmissionModel submission = new CopyleaksFileSubmissionModel(base64Content, "exam_template.txt", properties);

        Copyleaks.submitFile(authToken, scanId, submission);
        System.out.println("Template indexed successfully.");
        ```
    </CodeGroup>

    <Note>
      Make sure to keep track of the `scanId` (in this case `my-template-index`) as you will need it for the next step.
    </Note>
  </Step>

  <Step>
    ### Scan with template exclusion

    Now that you have a template indexed, you can submit a new document for scanning and tell Copyleaks to exclude the content of the template.

    Use the `properties.exclude.documentTemplateIds` field to specify the template ID.

    <CodeGroup>
        ```http title="HTTP" icon="globe"
        PUT https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission
        Content-Type: application/json
        Authorization: Bearer <YOUR_AUTH_TOKEN>

        {
          "base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
          "filename": "student_submission.txt",
          "properties": {
            "action": 0,
            "webhooks": {
              "status": "https://your-server.com/webhook/{STATUS}"
            },
            "exclude": {
              "documentTemplateIds": ["my-template-index"]
            },
            "indexing": {
              "repositories": [
                {
                  "id": "your-repo-id",
                  "includeMySubmissions": true,
                  "includeOthersSubmissions": true
                }
              ],
              "copyleaksDb": false
            },
            "aiGeneratedText": {
              "detect": true
            },
            "sandbox": true
          }
        }
        ```
        ```bash title="cURL" icon="terminal"
        curl -X PUT "https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission" \
             -H "Authorization: Bearer <YOUR_AUTH_TOKEN>" \
             -H "Content-Type: application/json" \
             -d '{
                   "base64": "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
                   "filename": "student_submission.txt",
                   "properties": {
                     "action": 0,
                     "webhooks": {
                       "status": "https://your-server.com/webhook/{STATUS}"
                     },
                     "exclude": {
                       "documentTemplateIds": ["my-template-index"]
                     },
                     "indexing": {
                       "repositories": [
                         {
                           "id": "your-repo-id",
                           "includeMySubmissions": true,
                           "includeOthersSubmissions": true
                         }
                       ],
                       "copyleaksDb": false
                     },
                     "aiGeneratedText": {
                       "detect": true
                     },
                     "sandbox": true
                   }
                 }'
        ```
        ```python title="Python" icon="python"
        import requests
        import base64

        # Student submission content
        student_content = "This is the student's answer mixed with template text."
        base64_content = base64.b64encode(student_content.encode()).decode('utf-8')

        url = "https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission"
        payload = {
            "base64": base64_content,
            "filename": "student_submission.txt",
            "properties": {
                "action": 0,
                "webhooks": {
                    "status": "https://your-server.com/webhook/{STATUS}"
                },
                "exclude": {
                    "documentTemplateIds": ["my-template-index"]
                },
                "indexing": {
                    "repositories": [
                        {
                            "id": "your-repo-id",
                            "includeMySubmissions": True,
                            "includeOthersSubmissions": True
                        }
                    ],
                    "copyleaksDb": False
                },
                "aiGeneratedText": {
                    "detect": True
                },
                "sandbox": True
            }
        }
        headers = {
            "Authorization": "Bearer <YOUR_AUTH_TOKEN>",
            "Content-Type": "application/json"
        }

        response = requests.put(url, json=payload, headers=headers)
        print(response.json())
        ```
        ```javascript title="JavaScript" icon="square-js"
        const axios = require('axios');

        const url = 'https://api.copyleaks.com/v3/scans/submit/file/student-exam-submission';
        const headers = {
            'Authorization': 'Bearer <YOUR_AUTH_TOKEN>',
            'Content-Type': 'application/json'
        };
        
        const data = {
            base64: "VGhpcyBpcyBhIHRlc3QgZG9jdW1lbnQu",
            filename: "student_template.txt",
            properties: {
                action: 0,
                webhooks: {
                    status: "https://your-server.com/webhook/{STATUS}"
                },
                exclude: {
                    documentTemplateIds: ["my-template-index"]
                },
                indexing: {
                    repositories: [
                        {
                            id: "your-repo-id",
                            includeMySubmissions: true,
                            includeOthersSubmissions: true
                        }
                    ],
                    copyleaksDb: false
                },
                aiGeneratedText: {
                    detect: true
                },
                sandbox: true
            }
        };

        axios.put(url, data, { headers })
            .then(response => console.log(response.data))
            .catch(error => console.error(error));
        ```
        ```java title="Java" icon="java"
        import classes.Copyleaks;
        import models.submissions.CopyleaksFileSubmissionModel;
        import models.submissions.properties.*;
        import java.util.Base64;
        import java.nio.charset.StandardCharsets;

        String scanId = "student-exam-submission";
        String base64Content = Base64.getEncoder().encodeToString("This is the student's answer mixed with template text.".getBytes(StandardCharsets.UTF_8));

        // Create submission properties
        SubmissionProperties properties = new SubmissionProperties(new SubmissionWebhooks("https://your-server.com/webhook/{STATUS}"));
        properties.setSandbox(true);

        // Set document templates to exclude
        SubmissionExclude exclude = new SubmissionExclude();
        exclude.setDocumentTemplateIds(new String[]{"my-template-index"});
        properties.setExclude(exclude);

        // Create and submit the file
        CopyleaksFileSubmissionModel submission = new CopyleaksFileSubmissionModel(base64Content, "student_submission.txt", properties);

        Copyleaks.submitFile(authToken, scanId, submission);
        System.out.println("Scan submitted with template exclusion.");
        ```
    </CodeGroup>

    <Tip>
      You can provide multiple template IDs in the `documentTemplateIds` array if you need to exclude content from multiple templates.
    </Tip>
  </Step>

  <Step>
    ### Summary
    You have just:

    - Created a template document and indexed it
    - Submitted a scan with template exclusion
    - Excluded template text from your plagiarism analysis
  </Step>
</Steps>

## Next steps
<CardGroup cols={2}>
  <Card title="Check for Plagiarism" icon="magnifying-glass" href="/guides/authenticity/detect-plagiarism-text">
    Detect plagiarism in text documents using the Copyleaks API. Search billions of sources to find unoriginal content.
  </Card>
  <Card title="Detect AI-Generated Content" icon="robot" href="/guides/ai-detector/ai-text-detection">
    Detect AI-generated text via sync or async API calls. This guide covers sync detection, see the Authenticity API Guide for async.
  </Card>
  <Card title="Assess Grammar and Writing Quality" icon="spell-check" href="/guides/writing/check-grammar">
    Get writing and grammar suggestions via API. Authenticate, submit text, and access full details in the docs.
  </Card>
  <Card title="Moderate Text" icon="shield-halved" href="/guides/moderation/moderate-text">
    Scan and moderate text content for unsafe or policy-relevant material across 10+ categories.
  </Card>
</CardGroup>
