What it provides
Four independent sub-analyses, each toggleable:- Sentiment — overall sentiment (
-1.0very negative to+1.0very positive) with a magnitude. - Entity extraction — named entities (people, organizations, locations, etc.).
- Topic classification — high-level categories (requires text ≥ 20 bytes).
- Content moderation — categories like
Toxic,Insult,Profanity,Derogatory,Sexual,Violent,Death, Harm & Tragedy,Firearms & Weapons,Illicit Drugs.
How it works
Calls Google Cloud Natural Language API:- v1 (classification, entities) for topic and entity extraction.
- v2 (sentiment, moderation) for sentiment and moderation scores.
Parameters
(Topic classification has no toggle; it always runs when input is
≥ 20 bytes.)
Outputs and metrics
Termination signals
Combine
moderation_flagged with max_moderation_confidence >= 0.65
for stricter control than the default 0.5 cutoff.
Limits and cost
Cost is Google Cloud Natural Language pricing — see the
NL pricing page.
Typical latency
500–3000 ms depending on enabled analyses and input length. The biggest saving you can make is disabling sub-analyses you do not need; each one is its own API call.When to use it
- Best as a flag, not a block. Sentiment and entity counts are noisy. Use them to enrich your analysis log; reach for safety guardrails or YARA when you actually want to block.
- Use moderation as a secondary signal. It overlaps with ShieldGemma but uses a different model family; agreement between the two raises confidence on a violation.
- Disable what you do not use. If you do not need topic
classification, the
include_*toggles already disable sentiment, entities, and moderation; topic always runs but is fast.
Failure modes
- NL API error → analyzer
ERRORstatus; surfaced inanalyzer_results. - Empty input → topic classification skipped; other sub-analyses produce empty results.
Next
- Combined analyzer — wiring NLP into termination rules.
- Safety & Responsible AI — the primary safety analyzer.