Sensitive Data Protection contains many built-in [infoType
detectors](https://docs.cloud.google.com/sensitive-data-protection/docs/concepts-infotypes), but you can also create your own. You can
customize detection behavior by defining your own *custom infoType detectors*,
so that Sensitive Data Protection will inspect or de-identify sensitive data that
matches patterns that you specify. The following are the types of custom
infoType detectors:

- *Regular custom dictionary detectors* are simple word and phrase lists that Sensitive Data Protection matches on. Use regular custom dictionary detectors when you have at most several hundred thousand words.
- *Large custom dictionary detectors* are generated by Sensitive Data Protection using large lists of words or phrases stored in either Cloud Storage or BigQuery. Use large custom dictionary detectors when you have a large list of words or phrases---up to tens of millions.
- *Regular expression (regex) detectors* let Sensitive Data Protection detect matches based on a regular expression pattern.
- *Metadata label detectors* let Sensitive Data Protection detect matches based on the presence of specific metadata. There are two types of metadata label detectors:
  - *Metadata key-value expression detectors* match on specific key-value pairs in content metadata.
  - *File label detectors* match on specific file labels, which can represent Google Drive labels or Microsoft sensitivity labels.
- *Surrogate infoType detectors* detect output from Sensitive Data Protection de-identification transformation [`CryptoReplaceFfxFpeConfig`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates#cryptoreplaceffxfpeconfig). This custom infoType detector is only used with the [`content:reidentify`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.content/reidentify.md.txt) method to reverse de-identification using format-preserving encryption (FPE) in FFX mode. For this reason, surrogates are not extensively described in these topics. For more information about how and when to use surrogate custom infoType detectors, see [Pseudonymization](https://docs.cloud.google.com/sensitive-data-protection/docs/pseudonymization.md.txt).

To refine scan results, you can [create inspection
rules](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-custom-infotypes-rules).

To learn more about custom infoType detectors, see the [InfoTypes and infoType
detectors](https://docs.cloud.google.com/sensitive-data-protection/docs/concepts-infotypes#custom) concept page. For several examples that
you can use or alter as you see fit, see [Examples of custom infoType
detectors](https://docs.cloud.google.com/sensitive-data-protection/docs/examples-custom-infotypes). The rest of this topic describes how to
use Sensitive Data Protection to create your own custom infoType detectors.

## Where to use custom infoType detectors

Custom infoType detectors are defined in the
[`CustomInfoType`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt#CustomInfoType)
object. You specify a `CustomInfoType` in the
[`InspectConfig`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt)
object when configuring the following:

- Inspection using [`projects.content.inspect`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.content/inspect.md.txt).
- Inspection jobs inside [`InspectJobConfig`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectJobConfig.md.txt).
- Inspection templates inside [`InspectTemplate`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.inspectTemplates#InspectTemplate).
- De-identification using [`projects.content.deidentify`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.content/deidentify.md.txt).
- De-identification templates inside [`DeidentifyTemplate`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.deidentifyTemplates.md.txt#resource-deidentifytemplate).
- Re-identification of content that has been de-identified with FPE in FFX mode using [`projects.content.reidentify`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.content/reidentify.md.txt). This scenario is specific to surrogate custom infoType detectors.

## API overview

The
[`CustomInfoType`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt#CustomInfoType)
object allows you to create a custom infoType detector for new content or to
fine-tune the results returned by pre-defined infoType detectors.

The `CustomInfoType` object is comprised of the following fields, which are set
as described:

- `"infotype"`: The name of the custom infoType detector, contained in an [`InfoType`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InfoType.md.txt) object.
- `"likelihood"`: The default [`Likelihood`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt#Likelihood) value to return for this custom infoType detector. You can specify alternate `Likelihood` values in `"detectionRules"` that will supersede this base `Likelihood` if the finding meets the criteria specified by the rule. If you don't include the `"likelihood"` field, the custom infoType detector defaults to `VERY_LIKELY`. For more information about likelihood, see the [Likelihood](https://docs.cloud.google.com/sensitive-data-protection/docs/likelihood.md.txt) concept page.
- `"detectionRules"`: A set of [`DetectionRule`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt#DetectionRule) objects to additionally apply to all findings of this custom infoType detector. This is where you specify hotword rules, as [`HotwordRule`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt#HotwordRule) objects. Rules are applied in the order in which they are specified. This field does not apply to `SurrogateType` objects.
- `"sensitivityScore"`: The
  [`SensitivityScore`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt#CustomInfoType.FIELDS.sensitivity_score)
  value to return for this custom infoType detector. If you don't include the
  `"sensitivityScore"` field, the custom infoType detector defaults to
  `VERY_LIKELY`.


  Sensitivity scores are used in [data profiles](https://docs.cloud.google.com/sensitive-data-protection/docs/data-profiles.md.txt). When
  profiling your data, Sensitive Data Protection uses the sensitivity scores of the infoTypes to
  [calculate the sensitivity level](https://docs.cloud.google.com/sensitive-data-protection/docs/sensitivity-risk-calculation.md.txt).


- One of the following fields, depending on the kind of custom infoType
  detector you're creating:

  - `"dictionary"`: A [`Dictionary`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/Dictionary.md.txt) object, which contains a list of words or phrases to search for.
  - `"regex"`: A [`Regex`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/Regex.md.txt) object, which contains a single pattern defining the regular expression.
  - `"surrogateType"`: A [`SurrogateType`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt#SurrogateType) object, if present, indicates that the custom infoType detector is a surrogate. For more information about how to use surrogate custom infoType detectors, see [Pseudonymization](https://docs.cloud.google.com/sensitive-data-protection/docs/pseudonymization.md.txt).
  - `"storedType"`: A reference to an existing [`StoredInfoType`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.locations.storedInfoTypes.md.txt) object. This field is required when creating a large custom dictionary detector. Although you can create regular dictionary detectors or regular expression detectors by defining this field, it's simpler to create those by defining the `dictionary` field or `regex` field respectively.
  - `"metadataKeyValueExpression"`: A [`MetadataKeyValueExpression`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt#MetadataKeyValueExpression) object that defines regular expressions for the key and value to search for in content metadata.
  - `"fileLabelInfoType"`: A [`FileLabelInfoType`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt#FileLabelInfoType) object that defines a Google Drive file label or Microsoft sensitivity label to search for.

## Next steps

Learn more about creating custom infoTypes from the following topics:

- [Create a regular custom dictionary detector](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-custom-infotypes-dictionary.md.txt): Learn how to create a custom infoType detector to match findings on a list of words and phrases.
- [Create a large custom dictionary detector](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-stored-infotypes.md.txt): Learn how to match findings on a very large list of words and phrases. Stored custom infoType detectors can match on up to tens of millions of words.
- [Create a custom regex detector](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-custom-infotypes-regex.md.txt): Learn how to create a custom infoType detector to match findings on a regular expression.
- [Create a custom metadata label
  detector](https://docs.cloud.google.com/sensitive-data-protection/docs/create-custom-infotypes-metadata-labels): Learn how to create a custom infoType detector to match findings in content metadata.
- [Modifying infoType detectors to refine scan
  results](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-custom-infotypes-rules): Learn how to create modifiers for both built-in and custom infoType detectors that can fine-tune scan results.
- [Customizing match likelihood](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-custom-infotypes-likelihood.md.txt): Learn how to use detection rules and hotwords to customize the likelihood values that are assigned to custom detector matches.
- [Examples of custom infoType detectors](https://docs.cloud.google.com/sensitive-data-protection/docs/examples-custom-infotypes.md.txt): Several example JSON custom infoType detector definitions that you can use or alter as you see fit.